C# Multiple Local Variable Declarations


In C#, you can use the comma to declare more than one local variable in a statement. The following displays the same −

int a = 20, b = 70, c = 40, d = 90;

Example

Let us see an example in which we are declaring multiple local variables. Below four variable is declared and initialized in the same statement.

Live Demo

using System;
class Demo {
   static void Main() {
      int a = 20, b = 70, c = 40, d = 90;
      Console.WriteLine("{0} {1} {2} {3}", a, b, c, d);
   }
}

Output

20 70 40 90

Updated on: 19-Jun-2020

581 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements