重载构造函数c#

本文关键字:构造函数 重载 | 更新日期: 2023-09-27 18:28:13

我有一个命名空间(DXApplication5)和两个类。我正试图用一个类刷新网格视图。下面的代码我做错了什么?Thx提前,

错误:最佳重载方法与匹配"DXApplication5.grid_refresh.grid_refresh(DXApplication5.Form1)"具有一些无效的参数

参数1:无法从"DevExpress.XtraEditors.XtraForm"转换为'DXApplication5.Form1'

public class grid_refresh
{
    public DXApplication5.Form1 frm1;
    public grid_refresh()
    {
        //Default Constructor   
    }
    public grid_refresh(DXApplication5.Form1 frm1)
    {
       frm1.gcStudent.Refresh();
    }        
}

//从另一类调用

 DXApplication5.grid_refresh gr = new grid_refresh(frm1);

重载构造函数c#

问题是您传递的frm1DevExpress.XtraEditors.XtraForm的实例,而不是DXApplication5.Form1

解决方案1:编写一个接受DevExpress.XtraEditors.XtraForm作为参数的构造函数。

 public grid_refresh(DevExpress.XtraEditors.XtraForm frm1)
 {
       ...
 }  

解决方案2:将frm1设为DXApplication5.Form1的实例。