To display a single variable value in C#, just use Console.WriteLine()
Let’s see an example. Here we are displaying the value of a single variable "a" in one line -
using System; using System.Linq; class Program { static void Main() { int a = 10; Console.WriteLine("Value: "+a); } }
To display the value of multiple variables in C# you need to do it in Console.WriteLine() Use the comma operator.
Let's look at an example. Here, we are showing the values of multiple variables "a" and "b" in one line -
using System; using System.Linq; class Program { static void Main() { int a = 10; int b = 15; Console.WriteLine("Values: {0} {1} ",a,b); } }
Above, {0} is replaced by the value of variable a, while { 1} is replaced by the value of variable b.
The above is the detailed content of Print single and multiple variables in C#. For more information, please follow other related articles on the PHP Chinese website!