C#中超级关键字的等价物

问题描述 投票:40回答:1

super关键字(java)的等效c#关键字是什么。

我的java代码:

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

现在我在C#中究竟需要等效的超级关键字,最初尝试使用base是否以正确的方式使用关键字base

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

谁能帮我吗。

java c# super base
1个回答
57
投票

C#相当于你的代码

  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);
     }
  }
© www.soinside.com 2019 - 2024. All rights reserved.