且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

参考柜台

更新时间:2023-12-01 17:25:04

Bill O写道:
有没有办法确定对象的引用数量?我只需要一个引用计数。
Is there a way to determine the number of references to an object? I only
need a reference count.




一个简单的方法是在类中添加一个静态计数器变量和

在构造函数中递增计数器。每次连续创建

和类的实例都会增加计数器。



A simple way would be to add a static counter variable to the class and
in the constructor increment the counter. Each successive creation of
and instance of the class will increment the counter.




" ;比尔奥 < billo @ _imt_net>在消息中写道

新闻:uT ************** @ TK2MSFTNGP09.phx.gbl ...

"Bill O" <billo@_imt_net> wrote in message
news:uT**************@TK2MSFTNGP09.phx.gbl...
有没有办法确定对象的引用数量?我只需要一个引用计数。

谢谢,
比尔
Is there a way to determine the number of references to an object? I only
need a reference count.

Thank you,
Bill




管理对象没有参考。由CLR计算,所以你不能得到数字

的参考资料。

如果你真的需要这个,你必须自己维护一个柜台。

好​​奇,你为什么需要这个?


Willy。



Managed object aren''t ref. counted by the CLR, so you can''t get the number
of references.
If you really need this you will have to maintain a counter yourself.
Just curious, why would you need this?

Willy.




Bill O &LT; billo @ _imt_net&GT;在消息中写道

新闻:uT ************** @ TK2MSFTNGP09.phx.gbl ...

"Bill O" <billo@_imt_net> wrote in message
news:uT**************@TK2MSFTNGP09.phx.gbl...
有没有办法确定对象的引用数量?我只需要一个参考计数。
Is there a way to determine the number of references to an object? I only
need a reference count.




一个普通的旧日常物品?我不这么认为。



A normal old every-day object? I don''t think so.