¡@

Home 

c# Programming Glossary: cast

Direct casting vs 'as' operator?

http://stackoverflow.com/questions/132445/direct-casting-vs-as-operator

casting vs 'as' operator Consider the following code void Handler.. 3 What is the difference between the three types of casting okay 3rd one is not a casting but you get the intent... and.. between the three types of casting okay 3rd one is not a casting but you get the intent... and which one should be preferred..

C# Interfaces. Implicit implementation versus Explicit implementation

http://stackoverflow.com/questions/143405/c-sharp-interfaces-implicit-implementation-versus-explicit-implementation

is accessible throuh your class you created when it is cast as that class as well as when its cast as the interface. Explicit.. created when it is cast as that class as well as when its cast as the interface. Explicit implentation allows it to only be.. Explicit implentation allows it to only be accessible when cast as the interface itself. myclass.CopyTo invalid with explicit..

When do you use the “this” keyword? [closed]

http://stackoverflow.com/questions/23250/when-do-you-use-the-this-keyword

. To invoke an extension method on the current instance To cast itself to another type You can avoid the first usage by declaring..

Cast int to enum in C#

http://stackoverflow.com/questions/29482/cast-int-to-enum-in-c-sharp

int to enum in C# What's a quick and easy way to cast an int to an enum in C# c# enums casting share improve this.. and easy way to cast an int to an enum in C# c# enums casting share improve this question From a string YourEnum foo..

Casting vs using the 'as' keyword in the CLR

http://stackoverflow.com/questions/496096/casting-vs-using-the-as-keyword-in-the-clr

implementation. What I've found is that I'm doing a lot of casting or object type conversion. What I'd like to know is if there.. who's provided insight and perspective on my question. c# casting clr share improve this question I don't think any of the.. variable. It's possible for the if to pass but then the cast to fail if another thread changes the value of randomObject..

When to use struct in C#?

http://stackoverflow.com/questions/521298/when-to-use-struct-in-c

a struct implements an interface as Enumerator does and is cast to that implemented type the struct becomes a reference type..

How do I convert Word files to PDF programmatically?

http://stackoverflow.com/questions/607669/how-do-i-convert-word-files-to-pdf-programmatically

but leave the Word application open. doc has to be cast to type _Document so that it will find the correct Close method... ref oMissing ref oMissing doc null word has to be cast to type _Application so that it will find the correct Quit method...

In C#, why can't a List<string> object be stored in a List<object> variable

http://stackoverflow.com/questions/6557/in-c-why-cant-a-liststring-object-be-stored-in-a-listobject-variable

in a List variable in C# and can't even be explicitly cast that way. List string sl new List string List object ol ol sl.. question Think of it this way if you were to do such a cast and then add an object of type Foo to the list the list of strings.. were to iterate the first reference you would get a class cast exception because once you hit the Foo instance the Foo could..

How do I convert an enum to a list in C#? [duplicate]

http://stackoverflow.com/questions/1167361/how-do-i-convert-an-enum-to-a-list-in-c

C# duplicate This question already has an answer here Cast int to enum in C# 10 answers How do I enumerate an.. all the values of an Enum. Enum.GetValues typeof SomeEnum .Cast SomeEnum If you want that to be a List SomeEnum just add .ToList.. want that to be a List SomeEnum just add .ToList after .Cast SomeEnum . To use the Cast function on an Array you need to..

Cast to Anonymous Type

http://stackoverflow.com/questions/1409734/cast-to-anonymous-type

to Anonymous Type I had the following problem today and I was.. to get 'a' to be of the right type var a new Id 0 Name a Cast a x Console.Out.WriteLine a.Id a.Name private static T Cast.. a x Console.Out.WriteLine a.Id a.Name private static T Cast T T typeHolder Object x typeHolder above is just for compiler..

Performance surprise with “as” and nullable types

http://stackoverflow.com/questions/1583050/performance-surprise-with-as-and-nullable-types

using this in performance sensitive situations... Results Cast 10000000 121 As 10000000 2211 LINQ 10000000 2143 Code using.. 2 i 3 values i null values i 1 values i 2 1 FindSumWithCast values FindSumWithAs values FindSumWithLinq values static void.. values FindSumWithLinq values static void FindSumWithCast object values Stopwatch sw Stopwatch.StartNew int sum 0 foreach..

How to RedirectToAction in ASP.NET MVC without losing request data

http://stackoverflow.com/questions/1936/how-to-redirecttoaction-in-asp-net-mvc-without-losing-request-data

Form Declare viewData etc. if TempData form null Cast TempData form to System.Collections.Specialized.NameValueCollection..

XML Serialization and Inherited Types

http://stackoverflow.com/questions/20084/xml-serialization-and-inherited-types

Override the Implicit Conversions Since the XmlSerializer Casts to from the required types implicitly. public static implicit.. unknown. public void ReadXml System.Xml.XmlReader reader Cast the Data back from the Abstract Type. string typeAttrib reader.GetAttribute.. Check the Type is Found. if type null throw new InvalidCastException Unable to Read Xml Data for Abstract Type ' typeof..

Preserving order with LINQ

http://stackoverflow.com/questions/204505/preserving-order-with-linq

a source element by index to a result element AsEnumerable Cast Concat Select ToArray ToList Preserves Order. Elements are filtered..

Why is the C# “as” operator so popular? [closed]

http://stackoverflow.com/questions/2139798/why-is-the-c-sharp-as-operator-so-popular

All that the above code does is to turn a useful InvalidCastException into a useless NullReferenceException . Am I the only.. public static T To T this object o Name it as you like As Cast To ... return T o and use a neat syntax obj.To SomeType .SomeMethod..

Why do C# Multidimensional arrays not implement IEnumerable<T>?

http://stackoverflow.com/questions/275073/why-do-c-sharp-multidimensional-arrays-not-implement-ienumerablet

on a multidimensional array which fails unless you use Cast T or similar so I can definitely see the an argument for making.. would be fine. If you want this you could either call Cast T if you're using .NET 3.5 or write your own method to iterate..

Cast int to enum in C#

http://stackoverflow.com/questions/29482/cast-int-to-enum-in-c-sharp

int to enum in C# What's a quick and easy way to cast an int..

When to use a Cast or Convert

http://stackoverflow.com/questions/3168704/when-to-use-a-cast-or-convert

to use a Cast or Convert I am curious to know what the difference is between.. post on another forum http en.allexperts.com q C 3307 Diff Cast Convert.htm Answer The Convert.ToInt32 String IFormatProvider..

Puzzling Enumerable.Cast InvalidCastException

http://stackoverflow.com/questions/445471/puzzling-enumerable-cast-invalidcastexception

Enumerable.Cast InvalidCastException The following throws an InvalidCastException.. Enumerable.Cast InvalidCastException The following throws an InvalidCastException . IEnumerable.. InvalidCastException The following throws an InvalidCastException . IEnumerable int list new List int 1 IEnumerable long..

Casting vs using the 'as' keyword in the CLR

http://stackoverflow.com/questions/496096/casting-vs-using-the-as-keyword-in-the-clr

vs using the 'as' keyword in the CLR I'm learning about.. values i 1 x values i 2 new object FindLengthWithIsAndCast values FindLengthWithIsAndAs values FindLengthWithAsAndNullCheck.. values static void FindLengthWithIsAndCast object values Stopwatch sw Stopwatch.StartNew int len 0 foreach..

How do I convert Word files to PDF programmatically?

http://stackoverflow.com/questions/607669/how-do-i-convert-word-files-to-pdf-programmatically

false foreach FileInfo wordFile in wordFiles Cast as Object for word Open method Object filename Object wordFile.FullName..

How can I use Entity Framework on an object graph past a depth of 2 with MySQL Connector / NET?

http://stackoverflow.com/questions/11676513/how-can-i-use-entity-framework-on-an-object-graph-past-a-depth-of-2-with-mysql-c

AS Description4 CASE WHEN Join3 . ShipId1 IS NULL THEN CAST NULL AS int WHEN Join3 . CrewMemberId IS NULL THEN CAST NULL.. CAST NULL AS int WHEN Join3 . CrewMemberId IS NULL THEN CAST NULL AS int ELSE 1 END AS C1 CASE WHEN Join3 . ShipId1 IS NULL.. ELSE 1 END AS C1 CASE WHEN Join3 . ShipId1 IS NULL THEN CAST NULL AS int ELSE 1 END AS C2 FROM dbo . Harbors AS Extent1 LEFT..

Is it possible to use SqlGeography with Linq to Sql?

http://stackoverflow.com/questions/2845767/is-it-possible-to-use-sqlgeography-with-linq-to-sql

level to return the column as a varbinary using the CAST statement. You can do this at the table level by adding a computed.. DDL like this ALTER TABLE FooTable ADD LocationData AS CAST Location AS varbinary max Then remove the Location column from..

SQL Server (2008) Pass ArrayList or String to SP for IN()

http://stackoverflow.com/questions/519769/sql-server-2008-pass-arraylist-or-string-to-sp-for-in

BEGIN IF SUBSTRING @list @index 1 ' ' BEGIN SELECT @id CAST SUBSTRING @list @start_index @index @start_index AS INT INSERT.. @index 1 END SELECT @index @index 1 END SELECT @id CAST SUBSTRING @list @start_index @index @start_index AS INT INSERT..

OracleParameter and IN Clause

http://stackoverflow.com/questions/541466/oracleparameter-and-in-clause

problem using Oracle parameters in SELECT IN

http://stackoverflow.com/questions/6155146/problem-using-oracle-parameters-in-select-in

a cast SELECT FROM tablename a where a.flokkurid in TABLE CAST manyNumbers AS number_table order by sjodategund rodun share..

Cast an Anonymous Types in Object and retrieve one Field

http://stackoverflow.com/questions/6901506/cast-an-anonymous-types-in-object-and-retrieve-one-field

e.Item or a better way if any . My problem I'm not able to CAST the e.Item Anonymous type Field Title and set it as Text Propriety..

How Can i display the output of SQL “PRINT” Command in C#?

http://stackoverflow.com/questions/8689336/how-can-i-display-the-output-of-sql-print-command-in-c

PRINT 'Number of students who chose ' @test ' is ' ' ' CAST @count1 AS VARCHAR MAX END SELECT @test Polls.a2 FROM Polls.. PRINT 'Number of students who chose ' @test ' is ' ' ' CAST @count2 AS VARCHAR MAX END SELECT @test Polls.a3 FROM Polls.. PRINT 'Number of students who chose ' @test ' is ' ' ' CAST @count3 AS VARCHAR MAX END SELECT @test Polls.a4 FROM Polls..

Return value from SQL Server Insert command using c#

http://stackoverflow.com/questions/9319532/return-value-from-sql-server-insert-command-using-c-sharp

var cmd INSERT INTO foo column_name VALUES @Value SELECT CAST scope_identity AS int using var insertCommand new SqlCommand..