假设A类是基类,然后你有A的B类子类(B类: A)。然后你有C类: B类。
问题是如果你在A类中有一个方法,那么C类可以使用这个方法吗?
发布于 2013-01-25 00:15:37
public class A
{
public int Id { get; set; }
protected int protectedId { get; set; }
private int privateId;
}
public class B : A
{
}
public class C : B
{
public C()
{
int temp = Id; // works
int temp1 = protectedId; // works
int temp2 = privateId; // does NOT work
}
}在其他的班级中;
public void SomeMethod()
{
C c = new C();
int i = c.Id; // works
int j = c.protectedId; // does NOT work
int k = c.privateId; // does NOT work
}https://stackoverflow.com/questions/14505709
复制相似问题