Auto-initializing C# lists

后端 未结 6 2150
有刺的猬
有刺的猬 2020-12-14 05:15

I am creating a new C# List (List). Is there a way, other than to do a loop over the list, to initialize all the starting values to 0?

6条回答
  •  太阳男子
    2020-12-14 06:00

    Use this code:

    Enumerable.Repeat(0d, 25).ToList();
    new List(new double[25]);     //Array elements default to 0
    

提交回复
热议问题