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.
我正在阅读 Jon Skeet 的《深入 C#》一书,其中有一部分让我感到困惑:
方法和嵌套类型可以是泛型的,但以下所有内容都必须是非泛型的: 字段 特性 索引器 构造函数 活动 终结者
方法和嵌套类型可以是泛型的,但以下所有内容都必须是非泛型的:
我测试并且字段(类中的变量)可以是通用的,我不明白吗?这让我怀疑其他人。
类和方法可以引入新的泛型类型参数,该列表中的其他类型参数可以基于该类型参数定义,但不能引入新的。
这一切都很好;
class ClassName<T>{ private T FieldName; private T PropertyName { get; set; } private R GenericMethod<R>(T t, R r) { ... } }
但不是;
class ClassName{ private T FieldName<T>; }