Possible Duplicate:
Direct casting vs 'as' operator?
Casting vs using the 'as' keyword in the CLR
object myObject = "Hello world.";
var myString = myObject as string;
object myObject = "Hello world.";
var myString = (string)myObject;
I have seen type conversion done both ways. What is the difference?
"as" will set the result to null if it fails.
Explicit cast will throw an exception if it fails.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With