title: How to add items in dictionary in which value is list of class?
body: <p>I am having a below dictionary :</p>
  
  <pre><code>Dictionary&lt;string, List&lt;Coordinates&gt;&gt; Coordinates = new Dictionary&lt;string,List&lt;Coordinates&gt;&gt;();
  
   public class Coordinates
      {
          public int Id { get; set; }
          public decimal range { get; set; }
          //other properties
      }
  </code></pre>
  
  <p>Now I am trying to add coordinates to my dictionary for specific region id and if same coordinates id comes then I don't want to add it.</p>
  
  <p>Below is my web service method: </p>
  
  <pre><code>public string MyMethod(string coordinateId, string regionId)
          { 
             var coordinates = Coordinates.Where(ed =&gt; (ed.Key == regionId)).SelectMany(ed =&gt; ed.Value).ToList();
  
             var coordinatesExist = coordinates.Any(ed =&gt; ed.Id.ToString() == id);
             if (!Coordinates.ContainsKey(regionId) &amp;&amp; !coordinatesExist)
              {
                     //here i want to add it but as it is list of my class i dont know how to add it  
                     Coordinates.Add(regionId, ?????);
              }
              else
              {
                 return "This coordinate id already exist for this region id";
              }
          }
  </code></pre>
  
  <p>I have check below link but those answers are with the list of string or with an array but not with the list of class:</p>
  
  <p><a href="https://stackoverflow.com/questions/10089850/c-sharp-dictionary-how-to-add-multiple-values-for-single-key">c# dictionary How to add multiple values for single key?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/15881960/how-to-add-values-to-dictionary-with-a-list-of-dictionaries-inside">How to add values to Dictionary with a list of dictionaries inside</a></p>
  
  <p><strong>Sample Data</strong> :</p>
  
  <pre><code>Region Id = 100
  Coordinate Id = 10,20,30
  
  Region Id = 200
  Coordinate Id = 10,20,30
  </code></pre>
  
  <ul>
  <li>1st call to Mymethod with RegionId = 100 and coordinate id =10 then I would like to have in my dictionary:<strong>Key = 100 , value = 10</strong></li>
  <li>2nd call to Mymethod with RegionId = 100 and coordinate id =20 then I would like to have in my dictionary:<strong>Key = 100 , value = 20</strong></li>
  <li>3rd call to Mymethod with RegionId = 100 and coordinate id =20 then I would like to have in my dictionary:
  <strong>I don't want to add this as 20 coordinate id already exist for regionId = 100</strong></li>
  </ul>