I have already a class that contains name and id and I'm also using lists method and including the name and id of each student.I'm also selecting a course from the combo box and selecting an index from the list box that contains names and id. The i.Name is generating an error, I have also tried writing All students.SelectedItem instead of i.Name ( That worked but It showed the name and id ) attached below is the screenshot of that [![enter image description here][1]][1] This is my code below
if (comboBox1.SelectedIndex != -1 && Allstudents.SelectedIndex != -1)
{
var query3 = from i in prod
where i == Allstudents.SelectedItem
select i.Name;
foreach(var i in query3)
{
var b = query3 ;
}
MessageBox.Show("The student" i.Name
"Has registered in the course" comboBox1.SelectedItem);