Sharad Gupta

Sharad Gupta

  • 92
  • 19.7k
  • 8.5m

Method Hiding in c#

Jan 17 2015 2:05 AM
 
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)