c# inline declare array code example

Example 1: c# inline array initialization

var array = new string[2]; // creates array of length 2, default values
var array = new string[] { "A", "B" }; // creates populated array of length 2
string[] array = { "A" , "B" }; // creates populated array of length 2
var array = new[] { "A", "B" }; // created populated array of length 2

Example 2: c# declare inline string array

string letter = (new[] {"a","b","c"}).AnyOne();
// or specifying the data type:
string letter = (new string[] {"a","b","c"}).AnyOne();