Join two list on a specified column

c#, list

Solution

List<first> flist= new List<first>();
List<second> slist= new List<second>();

var result = from f in flist
             join s in slist on f.ID equals s.ID into g
             select new {
                 f.name,
                 f.ID,
                 itemAttr = g.Any() ? g.First().itemAttr : null
             };

Problem

I am attempting to join two lists (flist and slist) on the ID column. List definitions, class definitions, list contents, and desired results are displayed below. ``` List<first> flist= new List<first>(); List<second> slist= new List<second>(); public class first { public string name { get; set; } public int ID{ get; set; } public string itemAttr { get; set; } } public class second { public int ID{ get; set; } public string itemAttr{ get; set; } } ``` List contents ``` flist: apples | 1 bananas| 2 trees | 3 slist: 1 | fruit 3 | not-fruit ``` Desired result: ``` flist: apples | 1 | fruit bananas | 2 | trees | 3 | not-fruit ```

Original source