Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ERROR "member names cannot be the same as their enclosing type"

Tags:

c#

I need to open a FrmEscalacao that sends information of FrmAdmin to FrmEscalacao with a string called "time"

here is the code of 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();
    }

}

here is the code of 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();

        }

And it returns an error at

private void FrmEscalacao (string time)
like image 538
Gianlucca Avatar asked Oct 16 '12 00:10

Gianlucca


2 Answers

You can have only constructor matching the name of the class. If it's the declaration of the constructor, then it should be

public FrmEscalacao(string time) {...}

Constructors should not have any return type. And you shouldn't declare it private, if it's going to be used to create an instanse of that type; it should be public.

Then you should use it:

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

that is, you must specify the value for time argument of type string.

like image 82
horgh Avatar answered Oct 24 '22 10:10

horgh


You need to pass an argument to the constructor.

So, either add another method as follows:

public FrmEscalacao()
{
    //all your code
}

Also, change your constructor to public void on the constructor that takes an argument.

public FrmEscalacao(string time)
{
    //all your code
}

Constructors automatically don't return anything, so you don't need to mark them void.

like image 36
user1877137 Avatar answered Oct 24 '22 12:10

user1877137