C# 中where关键字详解

where用于约束泛型

public class MyGenericClass<T> where T:IComparable {
    
     }

表示类型T只能是IComparable的子类

public class MyGenericClass <T> where T: IComparable, new()

new()只能出现在末尾
new()的意思就是说该类必须有公共的无参构造函数

猜你喜欢

转载自blog.csdn.net/qq_42068856/article/details/101461974