假設有繼承 A 的兩個 class,B 與 C,使用宣告在 class 中的 field 與 繼承來的 field,呼叫的方式不一樣在哪?
宣告在 class 中的 field : load field
繼承來的 field : call parent instance
public class A
{
int a;
public int Value
{
get { return a; }
}
}
public class B : A
{
int b;
public int Value
{
// IL_0002: call instance int32 ConsoleApplication4.A::get_Value()
get { return base.Value; }
}
}
public class C : A
{
int c;
public int Value
{
// IL_0002: ldfld int32 ConsoleApplication4.C::c
get { return this.c; }
// throw exception : stack overflow
// get{return this.Value; }
}
}
沒有留言:
張貼留言