Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Print Single and Multiple variable 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.
Advertisements