>我有以下(不完整的)方法定义
public static U Test<T, U>(string param1, T someType) where T: SomeType where U : ?
允许您返回任何类型(例如字符串、int)的正确语法是什么。即问号的位置应该是什么
如果你是一个类类型,并且你需要 Test 方法来返回一个实例化它的实例,那么你需要指定where U : new()
.这可以与 where 子句中的类型约束结合使用,例如 where U : ReturnType, new()
或where U : IReturnType, new()
.
您遇到什么编译错误?