Home  >  Article  >  Backend Development  >  Print single and multiple variables in C#

Print single and multiple variables in C#

王林
王林forward
2023-09-22 21:57:03762browse

在 C# 中打印单个和多个变量

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 -

Example

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 -

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, {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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete