加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

什么是C#泛型方法中的“where T:class”?

发布时间:2020-12-15 18:13:59 所属栏目:百科 来源:网络整理
导读:这些方法签名有什么区别? public void T MyMethodT(T parameter) 和 public void T MyMethodT(T parameter) where T : class 它们似乎有相同的结果……那么T:class的作用是什么? 解决方法 在第二种方法中,T只能是一个类,不能是结构类型. 见Constraints on
这些方法签名有什么区别?
public void T MyMethod<T>(T parameter)

public void T MyMethod<T>(T parameter) where T : class

它们似乎有相同的结果……那么T:class的作用是什么?

解决方法

在第二种方法中,T只能是一个类,不能是结构类型.

见Constraints on Type Parameters (C# Programming Guide):

where T : class

The type argument must be a reference [class] type; this applies also to any class,interface,delegate,or array type.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读