Difference between direct type casting and using "as" keyword?



Difference between direct type casting and using "as" keyword?..

Answer / amitabh dubey

Explicit cast throws an InvalidCastException if the object
can not be casted. you have to
Keep the casting under try / catch block to handle the
exception.
Instead you can use as operator which return null if it
can not cast the object.

Is This Answer Correct ?    25 Yes 0 No

Post New Answer

More C Sharp Interview Questions

How do you create user defined data types in c#?

0 Answers  


Do while loops yes or no c#?

0 Answers  


localization using windows c#

2 Answers  


Why do I get a "cs5001: does not have an entry point defined" error when compiling?

0 Answers  


What’s a strong name?

0 Answers  






Why do we need constructors?

0 Answers  


What are mutable and immutable types in c#?

0 Answers  


What are methods in C#?

0 Answers   Winsol Solutions,


What?s the C# equivalent of C++ catch (?), which was a catch-all statement for any possible exception?

1 Answers   Visual Soft,


What is different between Boxing and Unboxing?

0 Answers  


How do you remove the objects which are not in use?Explicitly or implicitly?What is the exact mechanism going behind?

2 Answers   Advanced Software Systems, Choice Solutions,


What is Implementation inheritance

0 Answers  


Categories