How can I find out how many objects are created of a class in C#?
You'd have to put a static counter in that was incremented on construction:
public class Foo
{
private static long instanceCount;
public Foo()
{
// Increment in atomic and thread-safe manner
Interlocked.Increment(ref instanceCount);
}
}
A couple of notes:
System.String created, for example - at least not without hooking into the debugging/profiling APIWhy do you want this information, out of interest?