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类型的扩展方法.
可能吗 ?什么是正确的语法?
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)
归档时间: |
|
查看次数: |
121 次 |
最近记录: |