title: Linq to avoid nested foreach loop to get unique values
body: <p>I have below query, but it has 2 foreach loops which i consider not good. How can i get distinct value from IEnumerable> object by using linq.</p>
  
  <p>Below is the code i have written,</p>
  
  <pre><code>var floatingIds= subInfo.Ranges.Select(c =&gt; c.RangeIDs.Select(s=&gt;s)).Distinct();
   var floatIds= new List&lt;Guid&gt;();
                  foreach (var ids in floatingIds)
                      foreach (var id in ids)
                      {
                          if (!floatIds.Contains(id))
                          {
                              floatIds.Add(id);
                          }
                      }
  </code></pre>
  
  <p>I have this post, but still am not getting expected values, but the above code gives correct IDs <a href="https://stackoverflow.com/questions/13541209/how-do-i-avoid-using-nested-foreach-statements-by-using-lambda-or-linq-in-this-s">How do I avoid using nested foreach statements by using lambda or linq in this scenario?</a></p>