c# - string Array initialization -
this question has answer here:
i have new array initialised below:
string[] somenames = new string[] { "john", "bryan", "annete", "mathiew", "joseph", "donald", "tom" }; string[] somenames = { "john", "bryan", "annete", "mathiew", "joseph", "donald", "tom" };
what difference? both gives same result. thought second 1 throw error. why both works , 1 preferred or more correct?
in first case, supply type of array element explicitly. however, c# compiler can figure out type of array element analyzing data supply. second example shows feature.
there absolutely no difference between 2 initializers. pick 1 style , use throughout code base consistency.
Comments
Post a Comment