Thread: how to call a second-level base class method

  1. #1
    Registered User
    Join Date
    Feb 2011

    Question how to call a second-level base class method

    Hi all
    I'm changing a C++ style code into C#, and naturally facing some problems. in the original C++ code I had 3 classes and a function in all of them, as shown below:
    public class A{
    public void tick();
    public class B: A
    public override void tick();
    public class C: B
    public override void tick(){
    A::tick();  //calling the second-level base class method
    how can I do such a thing?

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Oregon, USA
    You're looking at class-level functions instead of object-level functions, so you'd utilize static methods in C#:
        class A
            public static void Tick() { Console.WriteLine("In A."); }
        class B : A
            public new static void Tick() { Console.WriteLine("In B."); }
        class C : B
            public new static void Tick()
                Console.WriteLine("In C.");
        class Program
            static void Main(string[] args)
    In C.
    In A.
    In B.
    If you understand what you're doing, you're not learning anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Calling the overriden method from the base class
    By DavidP in forum C# Programming
    Replies: 2
    Last Post: 02-19-2010, 01:55 PM
  2. call a method from another to a class
    By vipur in forum Tech Board
    Replies: 7
    Last Post: 11-15-2009, 07:39 AM
  3. Replies: 5
    Last Post: 07-25-2008, 04:37 AM
  4. Replies: 9
    Last Post: 06-20-2008, 02:41 AM
  5. call base class function or derived class function
    By George2 in forum C++ Programming
    Replies: 4
    Last Post: 03-18-2008, 05:23 AM
Website Security Test