// b is really double[].
var b = new[] { 1, 1.5, 2, 2.5 };
Console.WriteLine("b is a: {0}", b.ToString());
// c is really string[].
var c = new[] { "hello", null, "world" };
Console.WriteLine("c is a: {0}", c.ToString());
// myCars is really SportsCar[].
var myCars = new[] { new SportsCar(), new SportsCar() };
Console.WriteLine("myCars is a: {0}", myCars.ToString());
Console.WriteLine();
}
Of course, just as when you allocate an array using explicit C# syntax, the items in the array’s
initialization list must be of the same underlying type (all ints, all strings, all SportsCars, etc.).
Unlike what you might be expecting, an implicitly typed local array does not default to
System.Object; thus the following generates a compile-time error:
Do'stlaringiz bilan baham: |