
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
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
- Related Articles
- What does an auto keyword do in C++?
- What does the operator || do in a var statement in JavaScript?
- What is the purpose of the var keyword in JavaScript?
- What does 'by' keyword do in Kotlin?
- What does the explicit keyword mean in C++?
- What does the restrict keyword mean in C++?
- What does the volatile keyword mean in C++?
- Difference between var keyword and short declaration operator in Golang
- What does the KEY keyword mean in MySQL?
- What does the interface ICollection do in C#
- What does the interface IEnumerable do in C#?
- What does the interface IList do in C#?
- What does the interface ICloneable do in C#?
- What does the interface IStructuralComparable do in C#?
- What does the interface IStructuralEquatable do in C#?

Advertisements