declare on - C#: Assign same value to multiple variables in single statement
Is there any way (just out of curiosity because I came across multiple same-value assignments to multiple variables today) in C# to assign one value to multiple variables at once in a single statements?
Something along these lines (pseudocode):
int num1 = 1; int num2 = 1; num1 & num2 = 5;
Probably not but I thought it was worth asking in case something similar is actually possible!
num1 = num2 = 5;
Note that this won't work in VB.
int num1, num2, num3; num1 = num2 = num3 = 5; Console.WriteLine(num1 + "=" + num2 + "=" + num3); // 5=5=5
Your example would be:
int num1 = 1; int num2 = 1; num1 = num2 = 5;
It is simple.
int num1,num2; num1 = num2 = 5;