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

What is the difference between type expression expressions? What's better?

// One way
var t:MyClass = MyClass(o);
// Another
var t:MyClass = o as MyClass;
+5
source share
1 answer

Oh, I knew that ...

Well, the first will fail if it cannot be ported to MyClass, i.e. you will get an exception flying up your stack.

The second will never throw, and you will only get a zero if proper selection cannot be made.

I think.

+8
source

All Articles