Quantcast
Channel: Null coalescing operator (??) with return - Stack Overflow
Browsing latest articles
Browse All 3 View Live

Answer by adjan for Null coalescing operator (??) with return

Well, because no one has implemented it this way. Or, more precisely, because return is not an expression. throw used to be a statement only prior to C# 7.0, but then was extended (due to a proposal)...

View Article



Answer by dialer for Null coalescing operator (??) with return

throw has relatively recently (in C# 7.0) been turned into an expression to enable this. return hasn't - it is always a just statement. The ?? operator requires an expression, not a statement. It was...

View Article

Null coalescing operator (??) with return

I was wondering why it is possible to do this in C# 7.0:int? test = 0;int test2 = test ?? throw new Exception("Error");..but not this:int? test = 0;int test2 = test ?? return;Can someone explain that?

View Article
Browsing latest articles
Browse All 3 View Live




Latest Images