Based on the code:
from i in this.GridViewFoo.SelectedItems select new EmployeeEntity { EmployeeID = (i as EmployeeDto).EmployeeID, Email = this.GetAllEmail((i as EmployeeDto).Email, (i as EmployeeDto).SecondaryEmails), EmployeeNumber = (i as EmployeeDto).EmployeeNumber, FirstName = (i as EmployeeDto).FirstName, LastName = (i as EmployeeDto).LastName }
After casting safely (i as EmployeeDto) I can get a NullReferenceException. How can I ensure and ensure the security of the code, and not overload it with a lot of null checks?
Solution Overview:
I did some tests to confirm whether the solutions worked. Both work well and bring the same result, you can check HERE . After that I did some performance tests with OfTypeSolution and letSolution .
As OfType's solution has the best times on average, it will be the answer!
source share