Is there a one statement or one line way to accomplish something like this, where the string s is declared AND assigned the first non-null value in the expression?
//pseudo-codeish
string s = Coalesce(string1, string2, string3);
or, more generally,
object obj = Coalesce(obj1, obj2, obj3, ...objx);
C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...
C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.
-= Subtract AND assignment operator. It subtracts the right operand from the left operand and assigns the result to the left operand. C -= A is equivalent to C = C - A.
As Darren Kopp said.
Your statement
object obj = Coalesce(obj1, obj2, obj3, ...objx);
Can be written like this:
object obj = obj1 ?? obj2 ?? obj3 ?? ... objx;
to put it in other words:
var a = b ?? c;
is equivalent to
var a = b != null ? b : c;
the ?? operator.
string a = nullstring ?? "empty!";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With