【问题标题】:Equivalent of Super Keyword in C#C#中超级关键字的等价物
【发布时间】:2013-07-03 10:29:18
【问题描述】:

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# 中的 super 关键字 最初尝试使用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);
   }
}

谁能帮帮我。

【问题讨论】:

  • 您必须更具体。你得到什么结果,你期待什么?另外,你为什么在 C# 中使用 Java 类?
  • 那说我猜你需要public Imagedata() : base(ResourceLoader.loadProperties(...))
  • “现在我需要转换成 C#,实际上我尝试使用 base,但我找不到从 java 获取的预期结果” 你期望什么?
  • 实际上使用 java 我可以从 processOperator 方法中提取正确的答案......但我需要通过在 .Net 环境中执行它来获得相同的结果......所以我尝试使用 base kewyword 但我知道我尝试的方式是错误的
  • @Ganeshja 好的,但我们不知道“正确答案”(或“错误”答案)是什么,也不知道如何测试您的代码以查看我们的答案是否正确。

标签: java c# super base


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2011-03-27
    • 1970-01-01
    • 1970-01-01
    • 2023-03-09
    • 2017-08-16
    • 2017-04-06
    • 2015-02-24
    • 2014-09-08
    • 2015-10-14
    相关资源
    最近更新 更多