use var keyword with more data types: arrays and collections. - CSharp Language Basics

CSharp examples for Language Basics:var

Description

use var keyword with more data types: arrays and collections.

Demo Code

using System;/*from  w ww.  j  a v a  2s.co m*/
using System.Collections.Generic;
class Program
{
   static void Main(string[] args)
   {
      // Use var for an array.
      var numbers = new[] { 1, 2, 3 };
      Console.WriteLine("Array initializer: ");
      foreach (int n in numbers)
      {
         Console.WriteLine(n.ToString());
      }
      // This writes "System.Int32[]".
      Console.WriteLine(numbers.GetType().ToString());
   }
}

Result


Related Tutorials