Implicitly-Typed Arrays

In the same way that you can declare an implicitly-typed variable, letting the compiler figure out the type of the variable’s value, you can declare implicitly-typed arrays.
In the example below, we declare and initialize both implicitly-typed variables and implicitly-typed arrays.  The compiler infers the type–shown in the associated comment.


1
2
3
4
5
6
7
// Implicitly-typed variables
var x = 42;         // int
var s = "Hooey";    // string
 
// Implicitly-typed arrays
var someArray = new[] { 5, 6, 7 };             // int[]
var arrB = new[] { new Dog("Bob"), null };     // Dog[]