Home > Backend Development > C#.Net Tutorial > Print single and multiple variables in C#

Print single and multiple variables in C#

王林
Release: 2023-09-22 21:57:03
forward
860 people have browsed it

在 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);
   }
}
Copy after login

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);
   }
}
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template