void Main() { int a; int b = 4; int c = b; } int a; int b; int c; void Main() { int a; int b = 4; int c = b; int d = 0; } int a; int b; int c; int d; before after +1
void HogeA() { … } } public class B : A { public void HogeB() { … } } public class C : B { public void HogeC() { … } } ΫϥεCͷΦϒδΣΫτ ΫϥεCͷใ ΫϥεBͷใ ΫϥεAͷใ this(࠷ॳઌ಄Λࢦ͢)
class Base { public virtual int GetId() { … } } public class A : Base { public override int GetId() { … } } public class B : A { public new int GetId() { … } } ΫϥεBaseͷΦϒδΣΫτ ΫϥεBaseͷใ ΫϥεBase༻ͷvtable ΫϥεAͷΦϒδΣΫτ ΫϥεBaseɾΫϥεAͷใ ΫϥεA༻ͷvtable ΫϥεBͷΦϒδΣΫτ ΫϥεBaseɾΫϥεAɾΫϥεBͷใ ΫϥεB༻ͷvtable
} } public class A : Base { public override int GetId() { … } } public class B : A { public new int GetId() { … } } ΫϥεBͷΦϒδΣΫτ ΫϥεBaseɾΫϥεAɾΫϥεBͷใ ΫϥεB༻ͷvtable ྫ͑ΫϥεBͷςʔϒϧใΛݟΔͱɺoverrideͨ͠GetId()Λ࣋ͭAଆͷؔϙΠϯλͱɺ newͰΫϥεB༻ʹ࠶ఆٛͨ͠GetId()ͷؔϙΠϯλ͕֨ೲ͞Ε͍ͯΔɻ A:GetId() B:GetId() vtableͷྫ vtableʹ͍ͭͯ