谁能告诉c#中下面提到的行的含义? [英] Can anyone please tell the meaning of undermentioned line in c#?
问题描述
公共抽象类BasePage< T> :页面T:class
public
:public access modifier所以你可以在任何引用此类的地方使用它。
abstract
:一个实现占位符而不能直接创建(你必须首先实现一个继承的) )。
class
:类定义(而不是接口
,struct
等。)
BasePage< t>< / t>
:基于定义的通用对象T $ / $
:Page
:以上内容继承自Page
定义
其中T:class
:T
的泛型定义的修饰符,因此它只能接受对象(所以你不能有BasePage< int>< / int>
等。)
引用:有人可以告诉c#中下面提到的行的含义吗?
行:
< pre lang =cs> public abstract class BasePage< T> :Page 其中 T: class
指你创建了一个抽象类 [ ^ ]派生自Page
。BasePage
类有一个通用类型参数 [ ^ ],T
,,其中T:class
表示当您创建BasePage $ c的新实例时$ c>,泛型类型参数必须是引用类型 [ ^ ],而不是值类型 [ ^ ]。如果将值类型作为泛型类型参数传递,则会出现编译器错误。
public abstract class BasePage<T> : Page where T : class
public
: public access modifier so you can use this anywhere which references this class.
abstract
: a placeholder for implementation and not creatable directly (you must implement a inherited one from this first).
class
: class definition (as opposed tointerface
,struct
etc.)
BasePage<t></t>
: a generic object based on the definition of T
:Page
: the above is inherited from thePage
definition
where T :class
: a modifier for the generic definition ofT
so it can only accept objects (so you can't haveBasePage<int></int>
etc.)
Quote:Can anyone please tell the meaning of undermentioned line in c#?
The line:
public abstract class BasePage<T> : Page where T : class
Means that you create an abstract class[^] that derives fromPage
. TheBasePage
class has one Generic Type Parameter[^],T
, and thewhere T : class
means that when you create a new instance ofBasePage
, the generic type parameter must be a reference type[^], not a value type[^]. If you pass a value type as generic type parameter, you get a compiler error.
这篇关于谁能告诉c#中下面提到的行的含义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!