嗨,我是新来的c#和Linq
.如果某个属性的值与其他lists属性的值匹配,我试图更新一个列表.
假设我有一个列表 firstlist
Name code ABC 101 DEF 201 GHI 301 JKL 401 MNO 101
第二个列表为 secondlist
description Code IT 101 ADMIN 201 Develeopment 301 Testing 401 Service 501
我希望我的结果列表为
Name code ABC 101 IT DEF 201 ADMIN GHI 301 Develeopment JKL 401 Testing MNO 101 IT
我试过这样的事,
var query = firstlist.Select(x => { x.Code = 101; return x.Code.ToString()+"IT"; })
但我想匹配来自secondlist
代替的101
代码和匹配代码我想更新firstlist
代码code+description
我不知道怎么做如果有人建议任何方式或链接将指导我将是伟大的.
*******更新*******
我想说的是@Sergey建议的那样
from x in firstlist join y in secondList on x.code equals y.Code select new { x.Name, code = String.Format("{0} {1}", y.Code, y.description) }
代替这个我可以做这样的事情
from x in firstlist join y in secondList on x.code equals y.Code select x.code = String.Format("{0} {1}", y.Code, y.description)
这将只更新现有listone
的代替每场比赛的创建新实体