我有这个:
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/