如何为类型参数添加2个new()约束?

smw*_*dia 1 .net c# generics syntax generic-constraints

我想要这样的东西:

public static TTo JumpTo<TFrom, TTo>(this TFrom from_page) 
       where TTo : new() TFrom : new()
{
    ...
}
Run Code Online (Sandbox Code Playgroud)

我想强制说TFrom和TTo都是从基类型派生的.

我想把这个方法作为TFrom类型的扩展方法.

可能吗 ?什么是正确的语法?

cad*_*ll0 9

where在每种类型之前放置关键字.

public static TTo JumpTo<TFrom, TTo>(this TFrom from_page) 
    where TTo : SomeBaseType, new() 
    where TFrom : SomeOtherBaseType, new()
{
     ...
}
Run Code Online (Sandbox Code Playgroud)