title: Count instances of the class
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/2392075/how-can-i-find-out-how-many-objects-are-created-of-a-class-in-c-sharp">how can i find out how many objects are created of a class in C#</a>  </p>
  </blockquote>
  
  
  
  <p>Is it possible to get number of instances which is active(created and not yet destroyed) for selected class?</p>
  
  <p>For example:</p>
  
  <pre><code>public class MyClass { }
  
  ...
  
  var c1 = new MyClass();
  var c2 = new MyClass();
  
  count = GetActiveInstances(typeof(MyClass))
  </code></pre>
  
  <p>Should return 2. If GC destroy any of these classes then 1 or 0.</p>