
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
What does the keyword var do in C#?
The "var" keyword initializes variables with var support. Just assign whatever value you want for the variable, integer, string, float, etc.
Example
using System; namespace Demo { class Program { static void Main(string[] args) { var myInt = 5; var myString = "Amit"; Console.WriteLine("Rank: {0}
Name: {1}",myInt,myString); } } }
Output
Rank: 5 Name: Amit
We can also use var in arrays −
Example
using System; namespace Demo { class Program { static void Main(string[] args) { var myInt = new int[] {65,43,88,56}; foreach(var val in myInt) Console.WriteLine(val); } } }
Output
65 43 88 56
Advertisements