this code :
var allSubjectsForAStudent = GetAllSubjects<Subject>(studentId);
returns an
IEnumerable<Subject>
and I can see bunch of subjects returned in the debugger.
Want to check for a particular Subject doing a case insensitive comparison.
This is the code that I have:
var studentSubjects = allSubjectsForAStudent.Where(s => s.Name.Equals(subjectName, StringComparison.CurrentCultureIgnoreCase));
'subjectName' is a parameter that the method will recieve.
When this line executes I get the 'Object not set to an instance of an object' error.
So what I want to do is a CASE INSENSITIVE search and return the first item when there are more than one and return an empty collection when there are none.
Any clues?
Edit 1
The answers suggest that there can be an entry in the first collection which might have a 'null'. While the observation is true the program makes sure that the 'Subject Name' can not be a null value. Hope this helps.
Thanks in advance.