Jiew Meng Jiew Meng -4 years ago 151
C# Question

C#: Is there any Difference between (Type)Something vs Something as Type


Possible Duplicate:

Direct casting vs 'as' operator?

Casting vs. using the as keyword in the CLR




In C#, whats the difference

var obj = (Array)Something


vs

var obj = Something as Array

Answer Source

first will throw a CastException if invalid. The second will only result in obj = null instead.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download