x to !

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

x to !

Postby Charles » Thu May 07, 2009 1:27 pm

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
Posts: 2514
Location: Los Angeles, CA

Return to Discussion

Who is online

Users browsing this forum: No registered users and 7 guests