Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# equivalent to JavaScript "OR assignment"

Tags:

javascript

c#

Does C# have an equivalent to JavaScript's assignment syntax var x = y || z;? In case you don't know, the result is not true/false. If y is defined, then it is assigned to x, otherwise z is assigned to x even if it is undefined.

Note that in JavaScript the variable still has to be declared: var test;

like image 731
Arlen Beiler Avatar asked Dec 17 '25 19:12

Arlen Beiler


1 Answers

I think that you are looking for ?? operator.

MSDN Reference

like image 161
Niccolò Campolungo Avatar answered Dec 20 '25 07:12

Niccolò Campolungo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!