how do I join two lists using linq or lambda expressions

后端 未结 3 1908
北荒
北荒 2020-12-07 16:41

I have two lists List and List I would like join the two lists on the workorder number as detailed below. In ot

3条回答
  •  无人及你
    2020-12-07 16:52

     public class State
            {
                public int SID { get; set; }
                public string SName { get; set; }
                public string SCode { get; set; }
                public string SAbbrevation { get; set; }
            }
    
            public class Country
            {
                public int CID { get; set; }
                public string CName { get; set; }
                public string CAbbrevation { get; set; }
            }
    
    
     List states = new List()
                {
                   new  State{  SID=1,SName="Telangana",SCode="+91",SAbbrevation="TG"},
                   new  State{  SID=2,SName="Texas",SCode="512",SAbbrevation="TS"},
                };
    
                List coutries = new List()
                {
                   new Country{CID=1,CName="India",CAbbrevation="IND"},
                   new Country{CID=2,CName="US of America",CAbbrevation="USA"},
                };
    
                var res = coutries.Join(states, a => a.CID, b => b.SID, (a, b) => new {a.CName,b.SName}).ToList();
    

提交回复
热议问题