​​Solutions to fix the NullReferenceException (part 3)



In .NET 5, use the null conditional operator ?., as shown below:



In the above example, std?.FirstName is like if(std != null) std.FirstName. The std?.FirstName checks if std is not null then only access the FirstName property.