Consider the following code snippet to follow my mind chronologically. The commented statements cannot be compiled.
var data1 = new int[3] { 1, 2, 3 };
var data2 = new int[] { 1, 2, 3 };
var data3 = new[] { 1, 2, 3 };
var data4 = new[] { 1, 2, 3.0f };
The simplification done for data3
and data4
is understandable.
int[] data5 = { 1, 2, 3 };
//var data6 = { 1, 2, 3 };
Unable to infer the declaration for data6
is understandable.
var data7 = new int[] { };
//var data8 = new [] { };
//int[] data9 = new [] { };
Unable to infer the declaration for data8
is also understandable.
What I don't understand is why data9
which is more informative cannot be compiled while data10
that is less informative can be compiled.
int[] data10 = { };
//var data11 = { };
Declaring data11
that cannot be compiled is also understandable.