C# different ways of casting -- (T)obj vs obj as T

Viewed 7117

Possible Duplicate:
casting vs using the 'as' keyword in the CLR

I have seen two different ways of casting in C#.

For example:

MyObj foo = (MyObj) bar; // this is what I see most of the times
MyObj foo = bar as MyObj; // I do see this sometimes
  • So, what is the basic difference?
  • What are the proper names for the style 1 and style 2 casting?
  • How do I decide when to use what?
  • Is there any major performance issues?
  • Is there anything else I should know of related to this topic?

Thanks a lot for looking into this :)

1 Answers
Related