public class Base
{
public int i = 10;
public virtual void Test()
{
Console.WriteLine(i);
}
}
public class Deliver : Base
{
public int i = 20;
public override void Test()
{
Console.WriteLine(i);
}
}
public class Class1
{
public static void Main(string[] args)
{
Deliver d = new Deliver();
Base b = d;
d.Test(); // 20
b.Test(); // 20
Console.WriteLine(b.i); // 10 问题就出在这,字段i并不支持多态。
}
}
{
public int i = 10;
public virtual void Test()
{
Console.WriteLine(i);
}
}
public class Deliver : Base
{
public int i = 20;
public override void Test()
{
Console.WriteLine(i);
}
}
public class Class1
{
public static void Main(string[] args)
{
Deliver d = new Deliver();
Base b = d;
d.Test(); // 20
b.Test(); // 20
Console.WriteLine(b.i); // 10 问题就出在这,字段i并不支持多态。
}
}