I was googling for and found no results for this. most of the people declare the array inside the void. like this
private void Something(){
ArrayList list = new ArrayList();
list.Add("awdawd");
}
but I have to declare the array outside of it because it would be used from different voids. this is my code:
public string[] Names= { "Rick", "Morty", "John" };
and for the db:
private void GetNames() {
string cmdText = "SELECT * FROM Login";
// using (SqlConnection cnn = new SqlConnection("Server=.\\SQLEXPRESS;Database=TestDB"))
using (SqlCommand SelectCommand = new SqlCommand(cmdText, connectionstring))
{
SqlDataReader myReader;
connectionstring.Open();
myReader = SelectCommand.ExecuteReader();
}
}
I tried to make it Names.add("Mario"); but it didnt work.
any suggestion?
Addmethod. If you want to useAdd, use aList<>instead of an array.ArrayListvoidbut a method (that doesn't return anything). Your methodGetNamesshould either return something(f.e. astring[]) or get a different name