Difference between casting by as and normal cast

G

Guest

I wondering what is the difference between the following two casts

DictionaryEntry entry = obj as DictionaryEntry;
AND

DictionaryEntry entry = (DictionaryEntry)obj;
 
Y

Yves Peneveyre

Hello !

The first one will return null if the types are not compatible instead of raising an exception for the second case.

Best Regards

Yves Peneveyre

I wondering what is the difference between the following two casts

DictionaryEntry entry = obj as DictionaryEntry;
AND

DictionaryEntry entry = (DictionaryEntry)obj;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top