2013-07-05 55 views
32

super關鍵字(java)的等效c#關鍵字是什麼?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); 
    } 

現在究竟是什麼,我需要super關鍵字的等同於C# 最初試圖與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); 
    } 
} 

關鍵字基地誰能幫我嗎。

+1

你必須要更加具體。你得到的結果是什麼,你期望的是什麼?另外,爲什麼你在C#中使用Java類? – millimoose

+3

這就是說我猜你需要'public Imagedata():base(ResourceLoader.loadProperties(...))'。 – millimoose

+0

*「現在我需要轉換成C#實際上我嘗試了基地,但我無法找到我從java中取得的預期結果」*你期望什麼? –

回答

40

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