ERROR "cannot be the same as their closing type"

I need to open FrmEscalacao, which sends FrmAdmin information to FrmEscalacao with a line called "time"

here is the FrmAdmin code

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 FrmEscalacao code

 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 in

 private void FrmEscalacao (string time) 
+6
source share
2 answers

You can only have a constructor matching the class name. If this is a constructor declaration, then it must be

 public FrmEscalacao(string time) {...} 

Constructors should not have any type of return. And you should not declare it private if it will be used to create instanse of this type; it must be public .

Then you should use it:

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

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

+4
source

You need to pass an argument to the constructor.

So add another method as follows:

 public FrmEscalacao() { //all your code } 

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

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

Constructors do not automatically return anything, so you do not need to specify their void.

+1
source

Source: https://habr.com/ru/post/927795/


All Articles