D J D J - 2 months ago 10
C# Question

How to define constraints on multiple generics parameters

I am wondering why I cant get such simple thing like this on google. This code is not compilable. How can I do this?

public class TestStep<StartEvent, CompletedEvent>
where StartEvent : MyBase1, MyInterface1, new() &&
where CompletedEvent : MyBase2, MyInterface2, new()
{
}


Please help.

Answer

Try without the "&&"

public class TestStep<StartEvent, CompletedEvent> 
    where StartEvent : MyBase1, MyInterface1, new()
    where CompletedEvent : MyBase2, MyInterface2, new()
{
}
Comments