First or default null (ARCH903)
Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.
Key dotnet.linq.first-or-default-null · Severity warning · Category linq
These methods return null when there is no match; direct access throws NullReferenceException.
Incorrect
Section titled “Incorrect”var user = users.FirstOrDefault(u => u.Id == id);return user.Name; // NRE if not foundCorrect
Section titled “Correct”var user = users.FirstOrDefault(u => u.Id == id);if (user is null) return null;return user.Name;Null-check the result before using it.