是否可以将对象引用传递给共享相同基类的类的方法签名?即,简化:
public class ClassA : System.Web.UI.Control
public class ClassB : System.Web.UI.Control
在页面中:
private void SetCurrentView(ref Control ctrl)
{
ctrl.Visible = true;
}
protected void Page_Load(object sender, System.EventArgs e)
{
aClass = new ClassA();
bClass = new ClassB();
SetCurrentView(ref aClass);
SetCurrentView(ref bClass);
}
显然,按原样,这是行不通的,并且在方法调用中强制转换它不是可分配的引用。想法?