Print Single and Multiple Variables in C#



To display single variable value in C#, you just need to use Console.WriteLine()

Let us see an example. Here, we have displayed the value of a single variable “a” in a line −

Example

using System;
using System.Linq;

class Program {
   static void Main() {
      int a = 10;
      Console.WriteLine("Value: "+a);
   }
}

To display multiple variables value in C#, you need to use the comma operator in Console.WriteLine().

Let us see an example. Here, we have displayed the value of multiple variables “a” and “b” in a line −

Example

using System;
using System.Linq;

class Program {
   static void Main() {
      int a = 10;
      int b = 15;
      Console.WriteLine("Values: {0} {1} ",a,b);
   }
}

Above, the {0} is replaced by the value of variable a, whereas {1} is replaced by the value of variable b.

Updated on: 2020-06-21T16:03:23+05:30

9K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements