Equivalent of Super Keyword in C#

Ganeshja picture Ganeshja · Jul 5, 2013 · Viewed 104.1k times · Source

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.

Answer

Dmitry Bychenko picture Dmitry Bychenko · Jul 5, 2013

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);
     }
  }