C#类的一个问题
如果有两个类 A,B:public class A
{
protected SqlConnection objSqlConnection;
public A
{
this.objSqlConnection = new SqlConnection("server=.;database=database_name;uid=sa;pwd=;");
}
// do something ...
}
public class B : A
{
//在这种情况下 base.objSqlConnection.open();可以用
base.objSqlConnection.open();
}
//但是下面的情况不能用,为什么?
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
如果有两个类 A,B,C:
public class A
{
protected SqlConnection objSqlConnection;
// do something ...
}
public class C
{
A a = new A();
// a.objSqlConnection.open();不可用
a.objSqlConnection.open();
}
public class B : A
{
//在这种情况下 base.objSqlConnection.open();可以用
base.objSqlConnection.open();
}