ECMA-334: 13. Conversions

Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio


Jump to: navigation, search
C# Language Specification
© 2006 ECMA International

13. Conversions

A conversion enables an expression of one type to be treated as another type. Conversions can be implicit or explicit, and this determines whether an explicit cast is required. [Example: For instance, the conversion from type int to type long is implicit, so expressions of type int can implicitly be treated as type long. The opposite conversion, from type long to type int, is explicit, so an explicit cast is required.

int  a = 123;
// implicit conversion from int to long
long b = a;       
// explicit conversion from long to int
int  c = (int) b;

end example] Some conversions are defined by the language. Programs can also define their own conversions (§13.4).


Today's Deals: Electronics

Personal tools