c# - 重载构造函数 C#

标签 c# constructor constructor-overloading

我有 1 个命名空间 (DXApplication5) 和 2 个类。我正在尝试用一个类刷新 gridview。下面这段代码我做错了什么?提前致谢,

Errors:The best overloaded method match for 'DXApplication5.grid_refresh.grid_refresh(DXApplication5.Form1)' has some invalid arguments

Argument 1: cannot convert from 'DevExpress.XtraEditors.XtraForm' to '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);

最佳答案

问题是 frm1你传递的是 DevExpress.XtraEditors.XtraForm 的一个实例, 不是 DXApplication5.Form1 .

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

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

解决方案 2:制作 frm1成为 DXApplication5.Form1 的实例.

关于c# - 重载构造函数 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34466030/

相关文章:

c# - 使用正则表达式匹配字符串,以特定字符串开头和结尾且中间不包含字符串

c# - 加密 azure 网站的数据库连接字符串

C#:DateTime.Now 月份输出格式

c++ - 构造一个对象,将其传递给基类构造函数以控制其生命周期

构造函数中的 Java Enum 无法解析为变量

c# - 我如何将 python 对象作为参数传递给 C# 程序

c++ - 当 `health` 不能高于 `maxHealth` 时,如何在一个对象中定义 `healt` 和 `maxHealth`?

scala - 不可变的案例类仍然能够更改参数值

java - java中的构造函数重载

C++如何生成函数重载的所有排列?