I have a program like
class A
{public void Foo() {
Console.WriteLine("Foo A");
}
}
class B : A
{
public virtual new void Foo() { Console.WriteLine("Foo B"); }
}
class C : B
{
public new void Foo() { Console.WriteLine("Foo "); }----------(1 type)
// or
new void Foo() { Console.WriteLine("Foo"); }----(2 type)
}
class Test:C
{
static void Main(string[] args)
{
C obj = new C();
obj.Foo();
Console.ReadKey();
}
}
when i execute this with type(1) ,the output is "foo" ,but when i execute this with type (2) then the output is "foo B" , what is difference b/w type1 and type2 in c class.

VulpesPosted Jan 17, 2015, 6:50 AM
However, in the case of type2, C.Foo() is private and obj.Foo() therefore looks up the inheritance chain to see if it can find an accessible Foo() method. It does so in the parent class, B, whose Foo() method is public, and so calls B.Foo() which prints 'Foo B'.