CSharp examples for Language Basics:var
Use var keyword with arrays and collections.
using System;//from w ww.ja va 2s . c om using System.Collections.Generic; class Program { static void Main(string[] args) { // Use var for a generic list type. // Note the use of the new collection initializer syntax, too. var names = new List<string> { "C", "B", "S", "M" }; Console.WriteLine("List of names: "); foreach (string s in names) { Console.WriteLine(s); } Console.WriteLine(names.GetType().ToString()); } }