c# - 错误 "member names cannot be the same as their enclosing type"

标签 c#

我需要打开一个 FrmEscalacao,它使用名为“time”的字符串将 FrmAdmin 的信息发送到 FrmEscalacao

这是FrmAdmin的代码

public partial class FrmAdmin : Form
{
    private string time;

    public FrmAdmin(string time)
    {
        InitializeComponent();

        this.time = time;
    }

    public void btnEscalar_Click(object sender, EventArgs e)
    {
        this.Hide();
        FrmEscalacao f1 = new FrmEscalacao();
        f1.ShowDialog();
    }

这是FrmEscalacao的代码

public partial class FrmEscalacao : Form
{
    public string time;

        private void FrmEscalacao (string time)
        {

            InitializeComponent();

            this.time = time;

            SQLiteConnection ocon = new SQLiteConnection(Conexao.stringConexao);
            DataSet ds = new DataSet();
            ocon.Open();
            SQLiteDataAdapter da = new SQLiteDataAdapter();
            da.SelectCommand = new SQLiteCommand("Here is the SQL command");
            DataTable table = new DataTable();
            da.Fill(table);
            BindingSource bs = new BindingSource();
            bs.DataSource = table;
            DataTimes.DataSource = bs;
            ocon.Close();

        }

它在

处返回错误
private void FrmEscalacao (string time)

最佳答案

您只能拥有与类名匹配的构造函数。 如果是构造函数的声明,那么应该是

public FrmEscalacao(string time) {...}

构造函数不应该有任何返回类型。你不应该将它声明为 private,如果它将被用来创建该类型的实例;它应该是public

那么你应该使用它:

FrmEscalacao f1 = new FrmEscalacao("your time"); 

也就是说,您必须为 string 类型的 time 参数指定值。

关于c# - 错误 "member names cannot be the same as their enclosing type",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12906009/

相关文章:

c# - c#中的不安全图像噪声去除(错误: Bitmap region is already locked)

c# - 仅通过 GDI+ 和 DotNet 指定大小来创建 Dib

c# - ASP.NET 将响应保存到 global.asax 中的文件

c# - 将两个 LINQ 表达式合并为一个

c# - 为什么 Windows 服务中的打印屏幕返回黑色图像?

c# - P/Invoke C++ DLL 以填充托管缓冲区

c# - 为什么这个多余的逗号可以编译?

c# - 关联范围内的日志消息

c# - Request.Cookies 为空

c# - 如何在不使用 GLUT 的情况下在 OpenGL 中绘制带纹理的环面?