C# Multiple Local Variable Declarations

CsharpServer Side ProgrammingProgramming

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
raja
Published on 24-Jul-2018 15:41:18
Advertisements