码迷,mamicode.com
首页 > 其他好文 > 详细

Linq中Select查询参数提取公共方法

时间:2014-11-26 22:12:31      阅读:185      评论:0      收藏:0      [点我收藏+]

标签:style   blog   ar   color   sp   on   div   log   bs   

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查询参数提取公共方法

标签:style   blog   ar   color   sp   on   div   log   bs   

原文地址:http://www.cnblogs.com/gossip/p/4125049.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!