Obviously the following is totally fine in c#;
int a;
int b = a = 2;
Is it possible to do multiple variable assignments in c# in a single statement?
i.e. something like;
int a = (int b = 2);
If we look at:
int a;
int b = a = 2;
That is essentially a=2; then b=a; (but without an extra eval). So we can get similar by reversing the order:
int a = 2, b = a;
However: I would say take this a bit hesitantly: please also prioritise readability.
Not as far as I know. The only variation I know of is:
int a = 2, b = 2;
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