lua - C#: using OR (short circuited version) for assignment -


in lua there nice feature checking if result of statement nil or not , using short circuited version of or react situation; such as:

text = gettextfromuser() or "default text" 

which translates assign return value of gettextfromuser() text , if gettextfromuser() returned nil, assign "default text" text

which nice trick use short circuit evaluation of or operator assignment.

i'm wondering if c# || operators has such capabilities or not. if no, shortest way achieve same behavior? ternary operator? if statement?

maybe null-coalescing operator? https://msdn.microsoft.com/en-ie/library/ms173224.aspx

string a; string b = ?? "default value"; 

so example become:

string text = gettextfromuser() ?? "default text" 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -