5 ms·
var foo = thing1 ?? thing2 ?? thing3 ?? bar; This will work.
by drewrv 15y ago
var foo = thing1 ?? thing2 ?? thing3 ?? bar;
This will work.
- halter73 15y ago"thing1 ?? thing2 ?? thing3 ?? bar" will return the value of the first non-null variable in the list. zmj wants something like Ruby's andand [1] instead. andand negates the need for an explicit null check on each property in a property lookup chain, which would normally be required to avoid a potential NoMethodError or NullReferenceException. You can create something similar [2] to andand in C# if you are willing to do property lookups using lambda expressions. [1] http://andand.rubyforge.org/ http://andand.rubyforge.org/ [2] http://stackoverflow.com/a/4958550 http://stackoverflow.com/a/4958550