title: “Grouping” dictionary by value of class property
body: <p>I have similar request like in below link</p>
  
  <p><a href="https://stackoverflow.com/questions/13410590/grouping-dictionary-by-value">&quot;Grouping&quot; dictionary by value</a></p>
  
  <p>But I want to group based on property of the class.</p>
  
  <pre><code>public class myClass1
  {
      public int id { get; set; }
      public string networkId { get; set; }
  }
  </code></pre>
  
  <p>In below example I want a group of networkId</p>
  
  <pre><code>        var obj1 = new myClass1() { id = 11, networkId = "asdf1" };
          var obj2 = new myClass1() { id = 22, networkId = "asdf2" };
          var obj3 = new myClass1() { id = 33, networkId = "asdf3" };
          var obj4 = new myClass1() { id = 44, networkId = "asdf1" };
          var obj5 = new myClass1() { id = 55, networkId = "asdf2" };
          var obj6 = new myClass1() { id = 66, networkId = "asdf1" };
          var obj7 = new myClass1() { id = 77, networkId = "asdf1" };
  
          var classDictionary = new Dictionary&lt;int, myClass1&gt;();
          classDictionary.Add(1, obj1);
          classDictionary.Add(2, obj2);
          classDictionary.Add(3, obj3);
          classDictionary.Add(4, obj4);
          classDictionary.Add(5, obj5);
          classDictionary.Add(6, obj6);
          classDictionary.Add(7, obj7);
  
          Dictionary&lt;myClass1, List&lt;int&gt;&gt; test2 =
                             classDictionary.GroupBy(r =&gt; r.Value.networkId)
                            //.ToDictionary(t =&gt; t.Key, t =&gt; t.Select(r =&gt; r.Value).ToList());
  </code></pre>
  
  <p>So that the result would be like, a dictionary with key value as per below</p>
  
  <pre><code>"asdf1" -&gt; List of obj1, obj4, obj6, obj7
  "asdf2" -&gt; List of obj2, obj5
  "asdf3" -&gt; List of obj3
  </code></pre>
  
  <p>Any help?</p>