0

C# で簡単な質問があります。

次のように、ジェネリック クラス (Box) 内にクラス (Properties) が埋め込まれています。

public class Box<E> where E : Box{
    public class Properties {
    }
}

外部クラスからサブクラス (プロパティ) への参照を作成するにはどうすればよいですか? このJavaステートメントに相当するものが必要です:

Shape<?>.Properties prop = new Shape<?>.Properties();

ありがとう

4

2 に答える 2

0

できません。Propertiesを必要としない場合の古典的な解決策は、E次のようなものです。

public class Box {
    // So that it can't be instantiated, or you could make the class abstract
    protected Box()
    {
    }

    public class Properties {
    }
}

public class Box<E> : Box {
}
于 2013-09-12T09:40:45.763 に答える