Alors que je suis en train de déboguer le code (dans WinForms C#), il affiche une erreurUtilisation de la variable locale non affecté
"l'utilisation de la variable locale non affecté" à 'arrlist [i]'
Puisque je le compare avec une variable de base de données, je ne peux pas initialiser la taille du tableau.
Voici le code:
if (count != 0)
{
OleDbCommand cmd1 = new OleDbCommand(
"select seat_no, booking_date, show_time "+
"from tickets "+
"where ticket_no = (select max(ticket_no) from tickets)", c);
OleDbDataReader oledb1 = cmd1.ExecuteReader();
oledb1.Read();
string retr_seats = oledb1.GetString(0);
char comma = ',';
string[] strarray = retr_seats.Split(comma);
int ticket_length = strarray.Length;
string[] arrlist;
int i = 0;
foreach(var control in this.Controls)
{
if(control is Label)
{
arrlist[i] = control.ToString();
i++;
}
}
for(var j=0;j<=ticket_length;j++)
{
for (var k = 0; k <= i-1; k++)
{
if (arrlist[k].Contains(strarray[j]))
{
MessageBox.Show(strarray[j]);
}
}
}
}
S'il vous plaît aidez-moi
On dirait que vous pourriez simplement mettre 'string [] arrList = new arrList [this.Controls.Count]'. – benjer3
En fait, pourquoi ne pas avoir 'string [] arrList = this.Controls.Select (x => x.ToString()). ToArray();'? – benjer3