public interface IAbc
{
int ID { get; set; }
}
public class CAbc : IAbc
{
public int ID { get; set; }
}
public partial class Default : System.Web.UI.Page
{
private void DoSome(ref IAbc abc)
{
}
protected void Page_Load(object sender, EventArgs e)
{
CAbc abc = new CAbc();
this.DoSome(ref abc);//报错了,Argument '1': cannot convert from 'ref CAbc' to 'ref IAbc'
}
}
大家来探讨一下,为什么
CAbc abc = new CAbc();
abc本来就是引用类型,再加ref当然会报错
object类型
protected void Page_Load(object sender, EventArgs e)
{
IAbc abc = new CAbc();//把CAbc改为 IAbc 就可以吧.
this.DoSome(ref abc);
}