Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
以下语句返回错误:
public class MySortedList<TKey, TItem> where TKey : struct, TItem : MyBaseClass<TKey>
MyBaseClass 定义如下:
public class MyBaseClass<T> where T : struct
错误出现在 TItem 之后的第二个“:”上 - “{ 预期” 正确的语法是什么? 谢谢你。
您需要使用多个where关键字,而不是用逗号分隔不同类型的约束:
where
public class MyBaseClass<T> where T : struct{} public class MySortedList<TKey, TItem> where TKey : struct where TItem : MyBaseClass<TKey> {}