0

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#???

1
  • 1
    Actually, you only have two generic abstract classes... Commented Aug 2, 2011 at 14:54

2 Answers 2

5

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.

Sign up to request clarification or add additional context in comments.

Comments

5

You could use a generic constraint:

public abstract class MyRootAbstractClass<W>
{
}

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

2 Comments

It doesn't compile, It demands to insert a generic type when implementing MyRootFatherClass (For example :MyRootFatherClass<M>)
Example Edit : public abstract class MyDerivedAbstractClass<W> where W : MyRootFatherClass <M> .JAVA doesn't demand to declare on generic type when declaring generic class (MyRootFatherClass) as constraint.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.