NullReferenceException When Using LINQ with Nullable Properties in C# 10
I'm stuck on something that should probably be simple... I'm working with a `NullReferenceException` when trying to filter a collection of objects using LINQ in C# 10. The objects in the collection have nullable properties, and I'm not sure how to handle them properly. Here's a simplified version of my classes: ```csharp public class Person { public string Name { get; set; } public int? Age { get; set; } } List<Person> people = new List<Person> { new Person { Name = "Alice", Age = 30 }, new Person { Name = "Bob", Age = null }, new Person { Name = "Charlie", Age = 25 } }; ``` I want to filter the list to get only those people who have an age greater than 20. My current LINQ query looks like this: ```csharp var filteredPeople = people.Where(p => p.Age > 20).ToList(); ``` However, when I run this code, I get a `NullReferenceException` on the line where I'm performing the filtering. I've tried adding a null check like this: ```csharp var filteredPeople = people.Where(p => p.Age.HasValue && p.Age > 20).ToList(); ``` But I still receive the exception. I've also checked that the collection `people` is not null at the time of filtering. Can someone guide to understand why this is happening? Is there a better way to safely filter nullable properties in C# 10 without running into exceptions? Any insights would be greatly appreciated! This is part of a larger service I'm building. Is there a better approach?