1

What's the difference of the two ways of array initialization? Are the same in all aspects?

using the new operator:

string[] arr = new array[3] {"a","b","c"};

and do not use the new operator:

string[] arr = {"a","b","c"};
Cœur
  • 34,719
  • 24
  • 185
  • 251
fluter
  • 12,243
  • 7
  • 51
  • 89
  • Second way is shorter. It is the difference. – Maxim Jun 18 '17 at 07:47
  • See https://stackoverflow.com/a/5678244/7565574. The latter one is just syntactical sugar which is basically internally converted to the first expression. – ckuri Jun 18 '17 at 07:49
  • The relevant part of the C# language specification: https://github.com/dotnet/csharplang/blob/master/spec/arrays.md#array-initializers – UnholySheep Jun 18 '17 at 07:50

0 Answers0