Jon*_*eet 13
您必须在构造中增加一个静态计数器:
public class Foo
{
private static long instanceCount;
public Foo()
{
// Increment in atomic and thread-safe manner
Interlocked.Increment(ref instanceCount);
}
}
Run Code Online (Sandbox Code Playgroud)
几个笔记:
System.String创建的实例数- 至少在没有挂钩调试/分析API的情况下也是如此为什么您不想要这些信息呢?