当我尝试调试此代码(在 C# WinForms 中)时,它显示错误
“使用未分配的局部变量”在“arrlist [i]”
由于我将它与数据库变量进行比较,因此我无法初始化数组的大小。
这是代码:
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]);
}
}
}
}
请帮我