Page 1 of 1

x to !

PostPosted: Thu May 07, 2009 1:27 pm
by Charles
The expression "x to !" casts a nilable type to its non-nilable type. It's a shorthand form. I'll explain the rest in code snippets:
# Consider if x is of type:
Dictionary<of String, int>?

# You could cast like this:
x to Dictionary<of String, int>

# But this is the same thing and easier:
x to !

# And this:
a = b to !

# Means that the local var "a" will be a non-nil type.

# If the cast fails because the expression is nil, then you will get a NonNilCastException

Also, see the UseNilAndNilableTypes How To