Tutorials References Exercises Videos Menu
Free Website Get Certified Pro

C# Multiple Variables


Declare Many Variables

To declare more than one variable of the same type, use a comma-separated list:

Example

int x = 5, y = 6, z = 50;
Console.WriteLine(x + y + z);

Try it Yourself »

You can also assign the same value to multiple variables in one line:

Example

int x, y, z;
x = y = z = 50;
Console.WriteLine(x + y + z);

Try it Yourself »