c# - 如何向 IEnumerable 添加一行

标签 c# ienumerable

我有一个 IEnumerable 类型的对象 result 和一个 Object 类型的对象 res。 我想连接两者,我该怎么做

IEnumerable<V_Student_Attendace_DayWise> result;
V_Student_Attendace_DayWise res;
result.Concat(res); // Error here...

最佳答案

Enumerable.Concat 方法需要一个集合作为它的参数,因此您必须将输入作为一个集合来进行连接。因此,此代码如下所示,其中 res 您已经拥有的对象

result = result.Concat(new[] { res});

你也可以试试这个:

result = result.Concat(new[] { new V_Student_Attendace_DayWise()});

关于c# - 如何向 IEnumerable 添加一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41032484/

相关文章:

c# - 添加到字典的不同方法

c# - 按一定顺序组合列表c#

c# - 使用本地线程的单元测试方法

c# - 先读取 IEnumerable 或等待其完成更改

c# - 将表达式传递给 IEnumerable Select

c# - 如何在 Application_BeginRequest 中执行击中网络服务器的第一个请求的部分代码?

c# - 为什么 IEqualityComparer<T> 有 GetHashCode() 方法?

c# - 'System.Collections.Stack' 到 'System.Collections.Generic.IEnumerable<int>'

c# - 何时使用 IEnumerable 与 IObservable?

c# - Collection.ToList<TResult>() 扩展方法引发编译时错误