首页 > 代码库 > Linq中Select查询参数提取公共方法
Linq中Select查询参数提取公共方法
class Program { static void Main(string[] args) { var listTest1 = new List<Test1> { new Test1{Key="1",Name="1"}, new Test1{Key="2",Name="2"}, new Test1{Key="3",Name="3"} }; var listTest2 = new List<Test2> { new Test2{SubKey="sub1",SubName="sub1",MainKey="1",}, new Test2{SubKey="sub2",SubName="sub2",MainKey="2"}, new Test2{SubKey="sub3",SubName="sub3",MainKey="2"} }; var result = from t1 in listTest1 join t2 in listTest2 on t1.Key equals t2.MainKey select new TestResult(t1, t2); result = result.ToList(); Console.WriteLine(result); Console.ReadKey(); } } public class Test1 { public string Key { get; set; } public string Name { get; set; } } public class Test2 { public string SubKey { get; set; } public string SubName { get; set; } public string MainKey { get; set; } } public class TestResult { public string Name { get; set; } public string SubName { get; set; } public TestResult(Test1 t1, Test2 t2) { this.Name = t1.Name; this.SubName = t2.SubName; } }
Linq中Select查询参数提取公共方法
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。