54

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.

Doc
  • 343
  • 3
  • 13
Ganeshja
  • 2,675
  • 12
  • 36
  • 57
  • 1
    You'll have to be more specific. What's the result you're getting and what were you expecting? Also, why are you using Java classes in C#? – millimoose Jul 05 '13 at 10:38
  • 4
    That said I'm guessing you need `public Imagedata() : base(ResourceLoader.loadProperties(...))`. – millimoose Jul 05 '13 at 10:40
  • *"Now i need to convert into C# actually i tried with base but i could not find my expected result as fetched from java"* what did you expect? – Marco Forberg Jul 05 '13 at 10:40
  • Actually using java i could extract the right answers from processOperator method ... but i need same set of results by executing it in .Net environment .. so i have tried with base kewyword but i knew the way i have tried is wrong – Ganeshja Jul 05 '13 at 10:41
  • @Ganeshja Okay but we do not know what the "right answers" (or the "wrong" ones) are or how to test your code at all to see if our answers are correct. – millimoose Jul 05 '13 at 10:42
  • @millimoose Thanks for u r quick response ... have edited my question in right way .. and more over u have solved my problem .. your post stating public Imagedata() : base(ResourceLoader.loadProperties(...)) actually solved my issue .. thanks – Ganeshja Jul 05 '13 at 10:52

1 Answers1

77

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);
     }
  }
AlexMelw
  • 2,406
  • 26
  • 35
Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215