I am wondering why this is really:
object[] array = {"bla bla bla..", 23, true};
But this is not so:
var array = {"bla bla bla..", 23, true };
var array2 = new [] {"bla bla bla..", 23, true };
In the second example, why the compiler cannot infer the type of the array according to the values in the array initializer? This seems very easy to use, especially compared to the typical output type. To define an array of objects, why should I explicitly specify the type of array?
var array = new object[] { "bla bla bla..", 23, true };
source
share