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
Post a Comment