zoukankan      html  css  js  c++  java
  • where T : class含义

    .NET支持的类型参数约束有以下五种:

    where T : struct                               | T必须是一个结构类型
    where T : class                                | T必须是一个Class类型
    where T : new()                               | T必须要有一个无参构造函数
    where T : NameOfBaseClass          | T必须继承名为NameOfBaseClass的类
    where T : NameOfInterface             | T必须实现名为NameOfInterface的接口

    泛型的Where

      泛型的Where能够对类型参数作出限定。有以下几种方式。

      ·where T : struct 限制类型参数T必须继承自System.ValueType。
     
      ·where T : class 限制类型参数T必须是引用类型,也就是不能继承自System.ValueType。

      ·where T : new() 限制类型参数T必须有一个缺省的构造函数

      ·where T : NameOfClass 限制类型参数T必须继承自某个类或实现某个接口。

      以上这些限定可以组合使用,比如: public class Point where T : class, IComparable, new()

  • 相关阅读:
    计算机网络基础知识整理
    计算机操作系统知识整理
    各类编程语言的主要用途
    计算机的基本组成知识整理
    对IT行业的看法和对软件工程的理解
    正规文法转换
    语法树评论
    c语言文法定义
    词法分析
    0909我对编译原理的见解
  • 原文地址:https://www.cnblogs.com/sunzhenyong/p/10155681.html
Copyright © 2011-2022 走看看