Add as
null-forgiving operator
#4796
-
Consider the case that we are somehow sure about the concrete type of a class and var x = obj as SomeType; //x will be SomeType?
var x = (obj as SomeType)!; But IMO it's kind of hard to write and even has made the code a bit ugly. var x = obj as! SomeType; One may argue that it would be ambiguous for the compiler to distinguish between this and the not operator. First, it should be connected with |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
Why not use a direct cast, i.e.?: var x = (SomeType)obj; It's faster, too, IIRC. |
Beta Was this translation helpful? Give feedback.
Why not use a direct cast, i.e.?:
It's faster, too, IIRC.