Click here to Skip to main content
15,914,500 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    abstract class A
    {
        public virtual void Meto()
        {
            Console.WriteLine("A");
        }
    }

    class B : A
    {
        public override void Meto()
        {

            Console.WriteLine("B");
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            A b = new B();


        }
    }
}


Now i want to call Meto of Class A.

Is there any way to achieve this.
Posted

C#
abstract class A
    {
        public virtual void Meto()
        {
            Console.WriteLine("A");
        }
    }

    class B : A
    {
        public new void Meto()
        {

            Console.WriteLine("B");
        }
    }

    class Program
    {

        static void Main(string[] args)
        {
            
            A b = new B();
            b.Meto();//Print "A"

            B bb = new B();
            bb.Meto();//Print "B"


            Console.ReadLine();

        }
    }
 
Share this answer
 
I think you'll find the answer in this link from the Microsoft documentation:
http://msdn.microsoft.com/en-us/library/k535acbf%28v=vs.71%29.aspx[^]
 
Share this answer
 
v2
Comments
Maciej Los 3-Apr-13 6:57am    
Short and to the point ;)
+5!
Kenneth Haugland 3-Apr-13 7:10am    
Thanks :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900