I have a problem with my code. I'm doing a crud with C# and I'm tring to find a student by id. In case you do not find any match I want to send a message saying that there is no student with that id. How can I do that?
I tried with a simple while:
while(i < count && !found)
{
s = studentList[i];
if (id.Equals(s.IdStudent))
{
found = true;
student = s;
}
i++;
}
if (found == false)
{
System.Console.WriteLine("There is no match");
}
And I'm trying this:
student = studentList.First(i => i.IdStudent == id);
if(student == null)
{
System.Console.WriteLine("There is no match");
}
It seems to be fine but when executing and using an id that is not in the list it tells me that I do not control the exception.