谁能告诉c#中下面提到的行的含义? [英] Can anyone please tell the meaning of undermentioned line in c#?

查看:76
本文介绍了谁能告诉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 ,泛型类型参数必须是引用类型 [ ^ ],而不是值类型 [ ^ ]。如果将值类型作为泛型类型参数传递,则会出现编译器错误。


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 to interface, struct etc.)
BasePage<t></t> : a generic object based on the definition of T
:Page : the above is inherited from the Page definition
where T :class : a modifier for the generic definition of T so it can only accept objects (so you can't have BasePage<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 from Page. The BasePage class has one Generic Type Parameter[^], T, and the where T : class means that when you create a new instance of BasePage, 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆