我有一个简单的类层次结构,其中有一个被覆盖的虚拟方法。但是在某些调用点我想调用这个方法的基类版本而不是虚拟方法。
例如:
public class A {
public virtual void Foo() {...}
}
public class B : A {
public override void Foo() {...}
}
public class Program {
public void SomeMethod()
{
...
// ListofA is type IEnumerable<A>
foreach (var item in ListofA)
{
// I want this to call A.Foo(), rather than B.Foo()
// But everything I've tried, which has really just been casting, has resulted in B.Foo()
item.Foo();
}
}
}