Direct array initialization with a constant value

前端 未结 6 1555
心在旅途
心在旅途 2020-12-09 14:44

Whenever you allocate a new array in C# with

new T[length]

the array entries are set to the default of T. That is null for th

6条回答
  •  醉话见心
    2020-12-09 15:06

    Similar to Dan's answer but without the need of using collections:

    int[] myArray = Enumerable.Repeat(-1, 100).ToArray();
    

提交回复
热议问题