Aug 15, 2011

C# is VS as

is (C# Reference)

Checks if an object is compatible with a given type. For example, it can be determined if an object is compatible with the string type like this:

if (obj is string)
{
}

as

The as operator is used to perform conversions between compatible types. The as operator is used in an expression of the form:
expression as type
is equivalent to:
expression is type ? (type)expression : (type)null
Note the use: 
ViewState["id"] = 10;
string s = ViewState["id"] as string. Then s will be null.

No comments:

Post a Comment