我有一个带有 ref 控件类型参数的方法,我想通过传递 ref 按钮类型参数来调用该方法。
那么编译器不接受这一点,我必须将引用控件类型更改为引用按钮类型。
Why ?
因为这会带来很多问题...
public void DoDarkMagic(ref Control control)
{
control = new TextBox();
}
public void Main()
{
Button button = new Button();
DoDarkMagic(ref button);
// Now your button magically became a text box ...
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)