When i am making left join i have this error. How to prevent error if id's doenot intersect?
Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
class Program
{
static void Main(string[] args)
{
List<Component> firstlist = new List<Component>();
List<Component> secondlist = new List<Component>();
firstlist.Add(new Component { id = 1, Name = "Jhon" });
secondlist.Add(new Component { id = 2, Name = "Jhon" });
var test = from d in firstlist
join i in secondlist
on d.id equals i.id
into a
from b in a.DefaultIfEmpty()
select new Component { id = b.id, Name = b.Name };
List<Component> Result = test.ToList();
}
public class Component
{
public int id { get; set; }
public string Name { get; set; }
}
}