Wednesday, March 9, 2016

If you try to cast something out of Session in C# with the as keyword and it's not really that type at all...

...you will end up with a variable of that type that is just null. Perhaps this won't work with things that cannot be null, but it will jive with a majority of types. I'm learning this is a C# distinction between casting with as versus casting with the type name in parenthesis. Also if you use the is keyword in lieu of the as keyword you can see if the thing in Session is even the type you anticipate in an if statement.

No comments:

Post a Comment