Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling a base class' method

Tags:

c#

oop

In c++ I would do

class A { public:     virtual void stuff()     {         //something     } };  class B : public A public:     virtual void stuff()     {         //something2         A::stuff() //something     } }; 

How would I do this in C#? I've tried

public void stuff() {     //something2     A.stuff(); //something } 

but that doesn't work

like image 383
Avery3R Avatar asked May 22 '11 20:05

Avery3R


People also ask

How do you call a base class method in overriding in C++?

Access Overridden Function in C++ To access the overridden function of the base class, we use the scope resolution operator :: . We can also access the overridden function by using a pointer of the base class to point to an object of the derived class and then calling the function from that pointer.


2 Answers

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

base.stuff(); 
like image 58
user541686 Avatar answered Oct 23 '22 00:10

user541686


Use base. Like base.stuff();

like image 29
Alex Aza Avatar answered Oct 22 '22 22:10

Alex Aza