While you do a null check in a search, you are not using your predicate. Line
foundItem = itemCollection.Find(item => item.item.ID == PDFID);
You can exclude it item null (have you added the null element to the collection?) Or item.item is null (are you sure it is always there?).
You can do:
foundItem = itemCollection.Find(item => item != null && item.item != null && item.item.ID == PDFID);
More chat, but you will not get a NullReferenceException .
Edit Ok, you changed your question. Now you do First . The First method will throw an exception if nothing is found. Instead, use FirstOrDefault , which will return null for the class or default value for the struct .
foundItem = itemCollection.FirstOrDefault(item => item != null && item.item != null && item.item.ID == PDFID);
Simon belanger
source share