4 ms·
"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. andan
by 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