c# - 如何在 IEnumerable<int> 中插入值?

标签 c#

我有这个:

IEnumerable<int> intYear = Enumerable.Empty<int>();

如何插入一些值?我没有看到任何 intYear.Add() 方法。

比如2010年、2011年等等...

最佳答案

你应该使用 IList<int>而不是 IEnumerable<int>为此:

IList<int> intYear = new List<int>();
intYear.Add(2011);
// and so on

IList<T>工具 IEnumerable<T>所以你可以将它传递给任何采用 IEnumerable<T> 的方法作为参数。

关于c# - 如何在 IEnumerable<int> 中插入值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8384318/

相关文章:

c# - ASP.NET 中的 P/Invoke(从 dll 读取/写入文本文件)

c# - 如何在 C# 中使用带下划线 (_) 的行继续符

c# - 使用变量的字典查找

c# - 开始参数的首字母缩写词的大写

c# - C# 支持 HierarchyId 吗?

c# - 检测 JSON 中 null 属性和省略属性之间的差异

c# - 我可以从两个字符的语言代码创建一个新的 CultureInfo 吗?

c# - 检查共享文件夹是否在 vb.net 中受密码保护

c# - 如何检查标准输入是否为空?

C# 将 byte[] 转换为带有字符集的字符串