2012-03-22 41 views
-3

なぜ私はC#で、このような何かを行うことはできません(擬似コードは以下の)インターフェイスの継承と派生クラス

Interface1 
{ 
    Method1(); 
} 

Interface2 : Interface1 
{ 
    Method2(); 
} 

Class1 : Interface1 
{ 
    Method1() 
    { 
    } 
} 

Class2 : Class1, Interface2 
{ 
    Method2() 
    { 
    } 
} 
+1

修正する必要がある質問やエラーはなんですか? – ashes999

+1

そのコードのほんの半分が有効なC#構文なので、おそらくです。コンパイルされない実際のC#コードがありますか? –

+0

メソッド名の前にインタフェース名と戻り値の型の前に 'interface'を使ってください。 –

答えて

3

することができます、あなたがインターフェイスを定義する際に自分の間違いを訂正し、あなたの戻り値の型を指定した場合メソッド。

interface Interface1 
{ 
    void Method1(); 
} 

interface Interface2 : Interface1 
{ 
    void Method2(); 
} 

class Class1 : Interface1 
{ 
    public void Method1() 
    { 
    } 
} 

class Class2 : Class1, Interface2 
{ 
    public void Method2() 
    { 
    } 
} 
2

これは可能です。

public interface Interface1 
{ 
    void Method1(); 
} 

public interface Interface2 : Interface1 
{ 
    void Method2(); 
} 

public class Class1 : Interface1 
{ 
    public void Method1() 
    { 
    } 
} 

public class Class2 : Class1, Interface2 
{ 
    public void Method2() 
    { 
    } 
} 
関連する問題