title: Distinct of Enumerable.Select of nested List in C#
body: <pre><code>public class Country
  {
      public List&lt;State&gt; States { get; set; } = new List&lt;State&gt;();
  }
  
  public class State
  {
      public List&lt;City&gt; Cities { get; set; } = new List&lt;City&gt;();
  }
  
  public class City
  {
      public decimal IdSeaLevel { get; set; }
  }
  </code></pre>
  <p><code>IdSeaLevel</code> Has these possible expected values: <code>0, 1, 2</code>.</p>
  <p>Then is needed to check al values inserted by user to prevent some different value.</p>
  <p>Suppose that the user send us an country (object of <code>Country</code> class) with its list filled (and nested too).</p>
  <p><strong>How to get all <strong><code>Distinct</code></strong> <code>IdSeaLevel</code> inserted value by the user?</strong></p>
  <p>I was thinking like:</p>
  <pre><code>List&lt;decimal&gt; AllowedIdSeaLevellist = new List&lt;decimal&gt;(new decimal[] { 0, 1, 2 });
  </code></pre>
  <p>Now, I get a Distict inserted Values</p>
  <pre><code>HashSet&lt;decimal&gt; SentIdSeaLevelSet = country.States
                  .Select(s =&gt; s.Cities.IdSeaLevel).ToHashSet();
  </code></pre>
  <p>Check</p>
  <pre><code>bool badRequest= SentIdSeaLevelSet
      .Where(s =&gt; AllowedIdSeaLevellist.All(a =&gt; a != s)).Any();
  </code></pre>