Casting - What's the difference between "(myObject)something" and "something As myObject" in C#?

Posted by SLC on Stack Overflow See other posts from Stack Overflow or by SLC
Published on 2010-04-12T13:26:00Z Indexed on 2010/04/12 13:33 UTC
Read the original article Hit count: 175

Filed under:

I've encountered this a couple of times and been perplexed.

Cat c = new Cat("Fluffy");
return (Animal)c;

Cat c = new Cat("Fluffy");
return c as Animal;

What's the reason for both of these syntaxes to exist?

© Stack Overflow or respective owner

Related posts about c#