Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent of Super Keyword in C#

Tags:

java

c#

super

base

What is the equivalent c# keyword of super keyword (java).

My java code :

public class PrintImageLocations extends PDFStreamEngine {     public PrintImageLocations() throws IOException     {         super( ResourceLoader.loadProperties( "org/apache/pdfbox/resources/PDFTextStripper.properties", true ) );     }        protected void processOperator( PDFOperator operator, List arguments ) throws IOException     {      super.processOperator( operator, arguments );     } 

Now what exactly I need equivalent of super keyword in C# initially tried with base whether the way I have used the keyword base in right way

class Imagedata : PDFStreamEngine {    public Imagedata() : base()    {                                                    ResourceLoader.loadProperties("org/apache/pdfbox/resources/PDFTextStripper.properties", true);    }     protected override void processOperator(PDFOperator operations, List arguments)    {       base.processOperator(operations, arguments);    } } 

Can any one help me out.

like image 649
Ganeshja Avatar asked Jul 05 '13 10:07

Ganeshja


People also ask

What is super keyword in C?

super means, calling the last implementor of a method (not base method) base means, choosing which class is default base in multiple inheritance.

Does C# have super keyword?

For super keyword in Java, we have the base keyword in C#.

What is this () and super ()?

The this() constructor refers to the current class object. The super() constructor refers immediate parent class object. It is used for invoking the current class method.

Is Super used in C++?

And C++ doesn't have a super or base keyword to designate “the base class”, like C# and Java do. One reason for this is that C++ supports multiple inheritance, which would make such a keyword ambiguous.


1 Answers

C# equivalent of your code is

  class Imagedata : PDFStreamEngine   {      // C# uses "base" keyword whenever Java uses "super"       // so instead of super(...) in Java we should call its C# equivalent (base):      public Imagedata()        : base(ResourceLoader.loadProperties("org/apache/pdfbox/resources/PDFTextStripper.properties", true))       { }       // Java methods are virtual by default, when C# methods aren't.      // So we should be sure that processOperator method in base class       // (that is PDFStreamEngine)      // declared as "virtual"      protected override void processOperator(PDFOperator operations, List arguments)      {         base.processOperator(operations, arguments);      }   } 
like image 148
Dmitry Bychenko Avatar answered Oct 09 '22 13:10

Dmitry Bychenko