title: Using Linq to check if a list includes null values in the middle
body: <p>I have a requirement where I need to filter out the null values from a list, only if the null value appears after the first non-null value and before the last non-null value.</p>
  
  <pre><code>Product one = new Product { Name="A" Priority="1" Value=null };
  Product two = new Product { Name="A" Priority="2" Value=null };
  Product three = new Product { Name="A" Priority="3" Value="10" };
  Product four = new Product { Name="A" Priority="4" Value=null };
  Product five = new Product { Name="A" Priority="5" Value="20" };
  Product six = new Product { Name="A" Priority="6" Value=null };
  </code></pre>
  
  <p>In the example, I need to first sort the list of products based on their priority and then check the first non-null value (ie., priority 3) and last non-null value (ie, priority 5), then get the list of all products with null values within priority 3 &amp; 5. So, in our example only Product 4 with Priority 4 is the record I am looking for.
  I got to the part of actually grouping them by products and sorting them by priority but stuck on how to proceed after that</p>
  
  <pre><code>from p in Products
  group p by p.Product into grp
  select new
  {
     Product = grp.Key
     Values = grp.OrderBy(x =&gt; x.Priority)
  }
  </code></pre>
  
  <p>Can someone point me as how to proceed? I am thinking I may to use the indexes to identify all the non-null and iterate through to get min and max Priority values and later query for all records with blank null values within the min/max priority.</p>