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

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain the ways to deploy an assembly?

603


Does c# support a variable number of arguments?

683


Define c# i/o classes?

612


What are the fundamental differences between value types and reference types?

619


What is thread pooling?

625






Explain the difference between access specifier and access modifier in c#?

577


What is a struct in C#?

635


What is method overriding in c#

678


What is command object in c#?

609


What do you mean by parsing and how to parse a date time string in c#?

602


What is dbml file in c#?

638


Does the system.exception class have any cool features?

600


What is a derived class in c#?

575


What is platform independence"?

624


How is exception handling implemented in c#?

681