Are there any advantages or disadvantages to using multiple assignment in a statement? In the simple example
var1 = var2 = true;
the assigment is right to left (as are all assignments in C#, I believe, and probably Java though I haven’t checked the latter). But are there any impacts (compiling, execution or otherwise) in coding this way?
Cheers.
An interesting set of responses, thanks. I’d thought I’d sum up (Is this allowed?)
I think then that perhaps it is acceptable, though not the preference of many, to use multiple assignment when declaring initial values of simple variables. But most agree that readability is far more important; their preference is separate statements. As is mine.
I did a further Google on this just now, and found that someone had tested “Performance and Multiple Assigment in C#” back in .Net 1.1. It seems there is a very small hit. Take a look.