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.
super means, calling the last implementor of a method (not base method) base means, choosing which class is default base in multiple inheritance.
For super keyword in Java, we have the base keyword in C#.
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.
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.
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); } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With