Calling a base class' method

base is the keyword for referencing your superclass in C#. Use:

base.stuff();

Use base. Like base.stuff();


Just to add to the answer above, base.stuff() works, unless it's the constructor you're trying to call in which case it is called as:

class A
{
public:
    public A(){}

};

class B : A
{
    public B() : base()
    {

    }
};

Comments

  1. Josiah

    • 2017/12/4

    I'll take the risk of stating the obvious: You call the function, if it's defined in the base class it's automatically available in the 

  2. Luca

    • 2016/7/25

    The base keyword is used to access members of the base class from within a derived class: Call a method on the base class that has been overridden by another method. Specify which base-class constructor should be called when creating instances of the derived class. A base class access is permitted only in a constructor, an instance method, or

  3. Crew

    • 2020/3/23

    By default, derived classes inherit all of the behaviors defined in a base class. In this lesson, we'll examine in more detail how member 

  4. Martinez

    • 2019/10/19

    Casting to base is another way to call Base::foo. Using a qualified-id to call a base class' function works irrespectively of what happens to that function in the derived class - it can be hidden, it can be overridden, it can be made private (by using a using-declaration), you're directly accessing the base class' function when using a

  5. Jesiah

    • 2017/8/6

    A derived Java class can call a constructor in its base class using the super keyword. In fact, a constructor in the derived class must call the super's 

  6. Theo

    • 2017/10/4

    If we derive a class from a base class and want to pass data from the constructor of the derived class to the constructor of the base class, it is necessary to call base constructor . In the inheritance hierarchy, always the base class constructor is called first. In c#, the base keyword is used to access the base class constructor as shown below.

  7. Crew

    • 2015/4/7

    The base keyword is used to access members of the base class from within a derived class: Call a method on the base class that has been 

  8. Chase

    • 2015/12/13

    Calling the base type Dispose method ensures that any resources created by the base type are released. How to fix violations. To fix a violation of this rule, call base.Dispose in your Dispose method. When to suppress warnings. It is safe to suppress a warning from this rule if the call to base.Dispose occurs at a deeper calling level than the

  9. Christopher

    • 2020/9/11

    Any virtual function calls execute the base class virtual functions, not the overriding functions in the (as yet unconstructed) derived class. But sometimes 

  10. Landen

    • 2020/9/18

    base (C# Reference) The base keyword is used to access members of the base class from within a derived class: Call a method on the base class that has been overridden by another method. Specify which base-class constructor should be called when creating instances of the derived class.

  11. Robinson

    • 2017/10/7

    When my base class's constructor calls a virtual function on its this object, why doesn't my derived class's override of that virtual function get invoked?

  12. Orlando

    • 2018/12/16

    If the base class' constructor takes arguments, you call it from a derived class using the base keyword and the following syntax: public class Base { public Base(string arg) { //this is called first

  13. Blaze

    • 2017/10/19

    In Inheritance, the child class acquires the properties of the base class or parent class. You can call the base class constructor from the 

  14. Walker

    • 2019/8/13

    If you need to call the base constructor in the middle of the override, then extract it to an actual method on the base class that you can call explicitly. The assumption with base constructors is that they're absolutely necessary to safely create an object, so the base will be called first, always.

  15. Kane

    • 2015/2/21

    Calling Parent class method after method overriding · Using Classname: Parent's class methods can be called by using the Parent classname.method 

  16. Caiden

    • 2017/10/20

    But what if an overridden method only calls the base class? Is this bad/good design? Bad design? No, rather bad implementation.

  17. Lee

    • 2019/12/11

    Calling a constructor of the base class If a constructor of the derived class needs to call the default constructor of the base type (the one 

Comments are closed.

Recent Posts