There was an error while loading. Please reload this page.
This page talks about preferred code style, reasons behind the particular choices, and sometimes a bit about the philosophy behind it all.
Equality operators can be overridden, operator is cannot
is
Good code
if (user is null) { return NotFound(); }
if (user is { } u) { return Ok(u.Name); }
Bad code
if (user == null) { return NotFound(); }
Fail Fast to reduce nesting, cognitive load, and sometimes even performance
if (thing is null) return NotFound(); thing.Name = newName; await _context.SaveChangesAsync(); return Ok(thing);
if (thing is not null) { thing.Name = newName; await _context.SaveChangesAsync(); return Ok(thing); } else { return NotFound(); }