我有以下两个列表:找出两个列表之间的共同元件用lambda表达式
var firstList = new List<ProgramInfo>()
{
new ProgramInfo {Name = "A", ProgramId = 1, Description = "some text1"},
new ProgramInfo {Name = "C", ProgramId = 2, Description = "some text2"},
new ProgramInfo {Name = "D", ProgramId = 3, Description = "some text3"},
new ProgramInfo {Name = "E", ProgramId = 4, Description = "some text4"}
};
var secondList = new List<ProgramInfo>()
{
new ProgramInfo {Name = "C", ProgramId = 2, Description = "some text1"},
new ProgramInfo {Name = "D", ProgramId = 3, Description = "some text2"},
};
这两个列表都在运行时产生的,我必须从两个该列表的选择根据程序ID的共同的ProgramInfo
例如,在上述例子的情况下,输出应该是
var thirdList = new List<ProgramInfo>()
{
new ProgramInfo {Name = "C", ProgramId = 2, Description = "some text1"},
new ProgramInfo {Name = "D", ProgramId = 3, Description = "some text2"},
};
public class ProgramInfo
{
public string Name { get; set; }
public int ProgramId { get; set; }
public string Description { get; set; }
}
有人建议我怎么能做到这一点使用lambda表达式?
这可能是一个错字,但不知道 - 我的' secondList'和'thirdList'的意思是''一些text2“'和''一些text3”'就像上面的列表中一样? –
不知道我在这里看到很多研究努力... –