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
  • 37,241
  • 25
  • 195
  • 267
fluter
  • 13,238
  • 8
  • 62
  • 100
  • 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