我想使用LINQ将数据库中的信息从使用SQLite制作成列表。然后我尝试使用从我的Windows应用商店应用页面上的两个文本框输入的文本来搜索该列表。一旦我尝试并使用列表,我会收到一个错误,指出“使用未分配的本地变量”。使用未分配的本地变量错误C#和LINQ
private void button_LINQ_Click(object sender, RoutedEventArgs e)
{
List<Notes> manyNotes;
int cursorPosition = TextBox_Results.SelectionStart;
var x = (from n in manyNotes
where (n.Note.Contains(textBox1.Text) && n.Note.Contains(textBox2.Text))
select n).ToList();
TextBox_Results.Text = TextBox_Results.Text.Insert(cursorPosition, "Notes containing " + textBox1.Text + " and " + textBox2.Text + ":\n");
foreach (Notes y in x)
TextBox_Results.Text = TextBox_Results.Text.Insert(cursorPosition, y.Note + "\n");
}
你在'manyNotes'里没有任何东西,它没有分配给任何东西,你不能使用它。 –