Sunday, June 1, 2008

as keyword for typecast [C# ASP.NET VS2005]

Usually in C or C++, we use this kind of typecast
float b = 10.9f;int a;
a = (int)b;
But the type that you are making type cast must be reference type such as object, primitive data type is not by reference but by value. So if you force using as like this example below it will give an error.
a = b as int;
//Error:The as operator must be used with a reference type ('int' is a value type)
Kindly refer to this tutorial for other reference.

No comments: