开发者

implement java function in c#

I have this generi interface and class in written in Java

public abstract class MyRootAbstractClass<W>
{
}

public abstract class MyDerivedAbstractClass<W extends MyRootFatherClass>
{
}

Notice :MyRootFatherClass (in MyDeriveAbstractClass declaration) doesn't asks for generic type (<W>).

Is any one knows How can i convert this code开发者_高级运维 to C#???


Looks to me like:

public abstract class MyRootAbstractClass<T>
{
}

public abstract class MyDerivedAbstractClass<T> where T : MyRootFatherClass
{
}

The where T : MyRootFatherClass is a generic type constraint so that you can't create a MyDerivedAbstractClass<T> for arbitrary T types - only MyRootFatherClass and subclasses.

Note that I've renamed W to T in order to follow .NET naming conventions.


You could use a generic constraint:

public abstract class MyRootAbstractClass<W>
{
}

public abstract class MyDerivedAbstractClass<W> where W : MyRootFatherClass
{
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜