gpt4 book ai didi

c# - 在 .NET 中使用整数填充列表的更简单方法

转载 作者:IT王子 更新时间:2023-10-29 03:37:27 24 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Populating a list of integers in .NET

除此之外,在 C# 中是否有更简单或更优雅的初始化整数列表的方法?

List<int> numberList = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

for(int i = 1; i <= 10; i++)
{
numberList.Add(i);
}

这似乎不太实用——尤其是当列表包含大量值时。循环会是更实用的解决方案吗?

谢谢,

抄送

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com