C# linq filter 加 concat

标签 c# .net linq

我有以下代码:

    var data= from row in table.AsEnumerable()
                           group row by row.Field<string>("id") into g
                           select new { Id= g.Key };

我想向数据变量中再添加 1 个元素。我该怎么做? (是否有类似 data.Concat(1) 等的东西

最佳答案

如果你想添加一个额外的 Id 你确实可以连接它:

data = data.Concat( new [] { new { Id= "1" } });

这是有效的,因为具有相同顺序的相同字段的匿名类型被编译为相同的类型。

关于C# linq filter 加 concat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5873391/

相关文章:

c# - .NET Core 中的自定义授权属性

.net - Visual Studio 2010 能否设置和部署 MSI 安装程序以通过客户端为 .NET 4.0 完整应用程序工作?

c# - String[] 中的部分匹配

c# - 如何将两个 Entity Framework 调用合并为一个?

C# 通用比较方法 [C++ 模板的模拟]

c# - Orchard 管理员用户页面选项卡不显示

c# - 调用 NavigationContext 时出现 NullReferenceException

.net - .NET 应用程序的插件设计

c# - FluentFTP - 连接 "Timed out trying to read data from the socket stream!"时出错

c# - Linq group 通过使用 Max 生成重复项