Casting - Which form is better - Pann's Thoughts

Casting - Which form is better

When casting (in C#) you generally have two options.

  • (Foo)myObj
  • myObj as Foo
  • Typicall, when I’m going to cast only one once and want to call a method on the casted object, I use

    ((Foo)myObj).Bar()

    The other day, I saw someone write

    (myObj as Foo).Bar()

    Which do you use (Vote here)

     

    Comments

    No Comments