形成产业.不能转换类型
本文关键字:转换 类型 不能 | 更新日期: 2023-09-27 18:10:05
我得到了EmployeeAccountPresenter
类,它应该与EmployeeAccountView
(继承自Form
类)和EmployeeBridge
类的对象操作。
namespace DBEmployee
{
class EmployeeAccountPresenter
{
public EmployeeAccountView form;
public EmployeeBridge bridge;
public EmployeeAccountPresenter(EmployeeAccountView _form, EmployeeBridge _bridge)
{
this.form = _form;
this.bridge = _bridge;
}
}
}
EmployeeAccountView
class:
namespace DBEmployee
{
class EmployeeAccountView : Form
{...
在我的Form1类我做:
namespace DBEmployee
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
EmployeeBridge eb = new EmployeeBridge();
EmployeeAccountPresenter eap = new EmployeeAccountPresenter(this, eb);
}
}
}
但是我在'this'参数中得到一个错误:
不能从'DBEmployee '转换。Form1"DBEmployee。EmployeeAccountView '
EmployeeAccountView
类继承自Form
类。为什么我不能转换?
this
为当前对象,类型为Form1
。Form1
是Form
的子类。
EmployeeAccountView
在任何地方都不起作用。
我猜你是想这样定义你的表单:
public partial class Form1 : EmployeeAccountView
现在this
将是EmployeeAccountView
的子类型,可以作为参数传递给EmployeeAccountPresenter
。