Why this matters
Prevents IndexOutOfRangeException and null dereferences.
Validate collection bounds and query results before indexing; prefer FirstOrDefault/SingleOrDefault with null checks.
Prevents IndexOutOfRangeException and null dereferences.
Side-by-side examples engineers can pattern-match during review.
var first = rows[0];var first = rows.FirstOrDefault(); if (first is null) return NotFound();var x = list[0];var x = list.FirstOrDefault(); if(x==null) return;From the same buckets as this rule.
Check if loops use equality operators (== or !=) in termination conditions. These can lead to infinite loops if the condition is never met exactly. Instead, use relational operators like < or > for safer loop termination.