CSharp examples for Language Basics:var
That's what "implicit type inference" means: "Let the compiler figure it out."
using System;/*from w w w.jav a 2s . c o m*/ class Program { static void Main(string[] args) { var i = 5; // Same as int i = 5; Console.Write(i.ToString() + " is a "); Console.WriteLine(i.GetType().ToString() + "\n"); var s = "Hello"; // Same as string s = "Hello"; Console.Write(s + " is a "); Console.WriteLine(s.GetType().ToString() + "\n"); var d = 1.0; // Same as double d = 1.0; Console.Write("{0:f1} is a ", d); Console.WriteLine(d.GetType().ToString()); } }