title: Linq left join null reference error
body: <p>When i am making left join i have this error. How to prevent error if id's doenot intersect?</p>
  
  <blockquote>
    <p>Unhandled Exception: System.NullReferenceException: Object reference
    not set to an instance of an object.</p>
  </blockquote>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
          List&lt;Component&gt; firstlist = new List&lt;Component&gt;();
          List&lt;Component&gt; secondlist = new List&lt;Component&gt;();
          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&lt;Component&gt; Result = test.ToList();
      }
  
      public class Component
      {
          public int id { get; set; }
  
          public string Name { get; set; }
      }
  }
  </code></pre>