Mike-Ward.Net

Tiny Trick for ViewState Backed Properties

Phil Haack’s blog has an excellent article on using the null coalescing operator with value types. I ran into to this very issue just the other night and like Phil quickly gave up. To summarize the trick.

bool result = (bool)ViewState["WillSucceed"] ?? false;

won’t compile but just change the casting order to (note the extra parenthesis):

bool result = (bool)(ViewState["WillSucceed"] ?? false);

and your in. Excellent tip!

← newer older →
.Net, Technology, Life, Whatever

Recent Posts

VSColorOutput for VS 2017 Released
Quick ReSharper tip for inline templates
NoSQL vs. NewSQL: What's the Difference?
Exploring Mithril, A JavaScript Framework for Building Brilliant Applications
Tweetz 1.1
Tweetz Desktop 1.0
Tweetz 0.11 Released
More... (1073)

Donate with PayPal