Possible Duplicate:
casting vs using the ‘as’ keyword in the CLR
Hi,
when to cast an object and when to use "as".
e.g:
class a= (class)object
and when to use
class a = object as class.
Possible Duplicate:
casting vs using the ‘as’ keyword in the CLR
Hi,
when to cast an object and when to use "as".
e.g:
class a= (class)object
and when to use
class a = object as class.
Using as is a safe option, as if the cast fails you do not get an exception, but the value returned is null.
If you want to get an exception when a cast is not possible, use ().
class a = object as class
this is not raise an exception in case it cannot cast and it wokrs only for reference types
This article seems to sum it up well...
http://gen5.info/q/2008/06/13/prefix-casting-versus-as-casting-in-c/