hopefully a pretty simple question this time. I have a Select method in a database connector class, which is as follows;
public List <string> [] Select(string mQuery)
{
//Create a list to store the result
List<string>[] datalist = new List<string>[1];
datalist[0] = new List<string>();
//Open connection
if (this.OpenConnection() == true)
{
//Create Command
MySqlCommand cmd = new MySqlCommand(mQuery, mConnection);
//Create a data reader and Execute the command
MySqlDataReader dataReader = cmd.ExecuteReader();
//Read the data and store them in the list
while (dataReader.Read())
{
datalist[0].Add(dataReader["id"] + "");
}
//close Data Reader
dataReader.Close();
//close Connection
this.CloseConnection();
//return list to be displayed
return datalist;
}
else
{
return datalist;
}
}
When i want to access “datalist” i’m assuming i call it like so;
results = mDB.Select(mQuery);
But because the returned value is a list, do i need to assign this variable to a new list, like so;?
List<string>[] results = new List<string>[1];
results[0] = new List<string>();
results = mDB.Select(mQuery);
string result = results[0].ToString();
MessageBox.Show(result);
This message box simply produces “System.Collections.Generic.List1(System.String)”
Any ideas about the logic of what i’m doing wrong?
Try not wrapping your list in an array?
Either way, the issue is that you were trying to display a list, which by default just returns it’s type. You should display the members of the list, not the list itself.