Development
Using Linq to find items in a List
Aug 23, 2016 · C#, LINQ
With the following data
public class Patient
{
public string Name { get; set; }
public string Id { get; set; }
}
and a list as follows
public List<Patient> myPatients;
we can find items with Linq
// find all patients that have a specific name
var patientsFound = patients.Where(p => p.Name.Equals(nameToFind));
// find the first or default patient that has a specific name
var patientFound = patients.Where(p => p.Name.Equals(nameToFind)).FirstOrDefault();