且构网

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

为什么我没有在c#windows窗体的属性窗口或窗体属性窗口中获取winsock控件的创建控件数组名称

更新时间:2023-12-06 12:38:04

你不能。

控件不知道它的存储位置。想一想:

You can't.
A control doesn't know where it is stored. Think about this:
MyClass mc1;
MyClass mc2;
MyClass[] array = new MyClass[10];
mc1 = new MyClass();
mc2 = mc1;
for (int i = 0; i < 10; i++)
   {
   array[i] = mc1;
   }

如果MyClass 的唯一实例 知道它的存储位置,它应返回什么值?

If the one and only instance of MyClass could know where it is stored, what value should it return?

mc1?
mc2?
array[0]?
...
array[9]?

进一步思考:要知道它存储的位置,它必须保留对位置的引用表示垃圾收集器无法处置该位置(因为它正被实例引用)或实例(因为它被该位置引用)。因此,没有任何东西可以处理,内存使用会增加,直到它耗尽...



我不知道你为什么要这样做:但我认为你需要重新考虑你到底需要什么!

And think even further: to "know" where it is stored, it would have to keep a reference to the "location" which means that the garbage collector could not dispose of the location (because it is being referenced by the instance) or of the instance (because it is being referred to by the location). So nothing could ever be disposed, and memory use would just increase until it ran out...

I don't know why you want to do this: but I think you need to reconsider what exactly you need this for!