linq多集合相连接

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace test_Console
{
    public class Man
    {
        public string Name { get; set; }
        public int Age { get; set; }       
    }
    public class Test
    {
        public string NameAge { get; set; }
        public string Name { get; set; }
    }
    public class Stu
    {
        public string Name { get; set; }
        public int Score { get; set; }
    }

    class Program
    {
        static void Main(string[] args)
        {
            List<Man> list = new List<Man>();
            for (int i = 0; i < 10; i++)
            {
                Man d = new Man();
                d.Age = i ;
                d.Name = i.ToString();
                list.Add(d);
            }
            List<Test> name = new List<Test>();
            for (int i = 5; i < 10; i++)
            {
                Test d = new Test();
                d.Name = i.ToString();
                name.Add(d);
            }

            List<Stu> s = new List<Stu>();
            s.Add(new Stu()
            {
                Name = "8",
                Score = 80
            });
            s.Add(new Stu()
            {
                Name = "7",
                Score = 70
            });


            var tsss = (from li in list
                                 join nm in name
                                 on li.Name equals nm.Name                                   
                                 join st in s 
                                 on li.Name equals st.Name
                                 where li.Age > 5
                                 select new  
                                 {
                                     Name = li.Name,
                                   NameAge = li.Name + li.Age.ToString(),
                                     Score = st.Score
                                   
                                 }).ToList();
                                 
            Console.WriteLine();
        } 
    }
}

  

posted @ 2021-05-08 00:32  艾特-天空之海  阅读(75)  评论(0编辑  收藏  举报