开发者

What is the difference between var t:MyClass = MyClass(o); and var t:MyClass = o as MyClass;

What is the difference bet开发者_StackOverflow社区ween this type casting expressions? What is better?

// One way
var t:MyClass = MyClass(o);
// Another
var t:MyClass = o as MyClass;


Oh, I used to know that one..

Ok, the first one will fail if it can't cast to MyClass, ie you'll end up with an exception flying up your stack.

The second one will never throw, and you'll only end up with a null value if a proper cast can't be made.

I think.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜