如何定义多个泛型参数的约束

D J*_*D J 33 c# generics

我想知道为什么我不能在谷歌这样简单的事情.此代码不可编译.我怎样才能做到这一点?

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

请帮忙.

Gre*_*Oks 58

尝试没有"&&"

public class TestStep<StartEvent, CompletedEvent> 
    where StartEvent : MyBase1, MyInterface1, new()
    where CompletedEvent : MyBase2, MyInterface2, new()
{
}
Run Code Online (Sandbox Code Playgroud)