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

What does readonly mean in c#?

745


What are actions in c#?

638


Why do we use readonly in c#?

670


Difference between value and reference type. What are value types and reference types?

721


Describe two uses of the “using” statement during the operation of c#?

725


Define a class and an object?

721


Define strong name in c#?

685


What is platform independence"?

734


Why do we need generics?

696


Hi Friends, I am going through Siemens Interview Procedure from last 1+1/2 months. I went through 1 written + 2 Technical + 1 Managerial Round process after which I got call from HR informing that "you are selected and we would like to meet you for HR round". HR round was very nominal compared to MR. HR Round last for hardly 5 mins. They told me that you will get the final result on Friday. Still I have not received any feedback from them. Please help!!!

16883


Which programming language is best for desktop applications?

669


What is the difference between abstract and abstraction?

646


Explain the steps to create satellite assembly?

666


what is a constructor? What is a destructor?

727


Can struct inherit from class c#?

713