【发布时间】:2017-03-30 01:26:15
【问题描述】:
我有 2 个列表 groupoptions 和 dataIndicator
class groupoptions{
...
GroupName string
}
class dataIndicator{
...
HeaderID int
IndicatorDescription
}
目前我的组名可能值为 4 或 5 或 11
首先我想获取所有 headerid 等于 GroupName 的 dataindicators,然后用 dataindicator 的 IndicatorDescription 替换这些 GroupNames
Linq 的语法是什么?
更新
使用连接
var newList = from first in dataIndicator
join second in groupedoptions
on first.HeaderID.ToString() equals second.GroupName
select new { first,second };
接下来呢? 问题:我想在 Linq Select 中创建的构造函数中执行此操作
var list = xyz.Select(x => new groupoptions(){
GroupName = x.Key.ToString();
})
【问题讨论】:
-
您尝试了哪些方法,但以何种方式不起作用?
-
我正在使用 dataIndicator.GetEnumerator 但想要一/两行 linq 语法
-
尚未使用(getenumerator)
-
能否提供有效的 C# 代码和一些示例数据(也在 C# 中)?
-
代码已更新,如果您需要其他内容,请告诉我