1
Answer

Method Hiding in c#

Sharad Gupta

Sharad Gupta

9y
644
1
 
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.
 
 
 

Answers (1)