控件保持值 [英] The controls maintain the values
本文介绍了控件保持值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我将一个未在屏幕上显示的控件作为参数而不是通过引用传递给函数,并且我修改了其中一个值,则控件将保持该值。这个机制如何运作?
我尝试过:
您尝试了什么?>您尝试了什么?
If I pass to a function a control that does not show on the screen as a parameter, not by reference, and I modify one of its values, the control maintains the value. How does this mechanism work?
What I have tried:
What have you tried?>What have you tried?
推荐答案
Control是一个类,因此控件的所有实例都是类实例 - 这使它们成为引用类型。基于结构的实例(如Int32,Point等)是非常不同的值类型。
这意味着即使你调用一个方法并将一个实例作为参数传递,你也会传递一个引用。
有看看这里:使用结构和类 - 这是什么约? [ ^ ] - 它有点详细,但它确实解释了它的意义以及为什么你得到了你观察到的效果。
A Control is a class, so all instances of controls are class instances - which makes them Reference Types. Struct based instances (like Int32, Point, and so on) are Value Types which are very different.
And that means that even when you call a method and pass an instance as a parameter, you pass a reference to it.
Have a look here: Using struct and class - what's that all about?[^] - it gets a little detailed, but it does explain what it all means and why you get the effect you observe.
这篇关于控件保持值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文