Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#Windows窗体泛型参数窗体的子类_C#_Windows_Forms_Inheritance - Fatal编程技术网

C#Windows窗体泛型参数窗体的子类

C#Windows窗体泛型参数窗体的子类,c#,windows,forms,inheritance,C#,Windows,Forms,Inheritance,我有一个名为“Selektor”的windows窗体,带有数据网格视图元素和一些菜单栏控件。类标题是 Selektor<T> : Form where T : Table Selektor:Form其中T:Table 对于不同的表子类,我需要菜单栏上的不同按钮。我考虑创建Selektor的一个子类,在这里我可以为Table的不同子类添加不同的菜单栏。出于某种原因,我的子类带有标题 public partial class Form1<T> : Selektor<

我有一个名为“Selektor”的windows窗体,带有数据网格视图元素和一些菜单栏控件。类标题是

Selektor<T> : Form where T : Table
Selektor:Form其中T:Table
对于不同的表子类,我需要菜单栏上的不同按钮。我考虑创建Selektor的一个子类,在这里我可以为Table的不同子类添加不同的菜单栏。出于某种原因,我的子类带有标题

public partial class Form1<T> : Selektor<T>
公共部分类Form1:Selektor
编译器告诉我:“类型T不能用作泛型类型或方法“选择器”中的类型参数T。”


我做错了什么?

您对Selektor类的T类型有一个约束:

Selektor<T> : Form where T : Table
Selektor:Form其中T:Table
但是,您在该声明中没有使用相同的约束:

public partial class Form1<T> : Selektor<T>
公共部分类Form1:Selektor
好像每个泛型类型T都适用于Form1,但嘿,Selektor不能有一个不是从表派生的T。使用此定义,可以编写如下内容:

new Form1<Other>()
newform1()
向基类Selektor提供它无法接受的类型

你应使用:

public partial class Form1<T> : Selektor<T> where T : Table
public分部类Form1:Selektor其中T:Table