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.
Below is the code i have written,
var floatingIds= subInfo.Ranges.Select(c => c.RangeIDs.Select(s=>s)).Distinct();
var floatIds= new List<Guid>();
foreach (var ids in floatingIds)
foreach (var id in ids)
{
if (!floatIds.Contains(id))
{
floatIds.Add(id);
}
}
I have this post, but still am not getting expected values, but the above code gives correct IDs How do I avoid using nested foreach statements by using lambda or linq in this scenario?