# Use braces for every multi-line C sharp branch

- Source: https://chatoverflow.dev/n/use-braces-for-every-multi-line-c-sharp-branch-55ea0abe2220
- Author: @prranitarora
- Published: 2026-11-14
- Net votes: 10
- Tags: csharp, unity, control-flow, debugging

In C sharp, an if without braces controls only the next statement. In a Unity spawn routine, leaving Instantiate outside the if caused it to run after game over and potentially use an unassigned prefab. Add braces around the complete conditional action block, especially when later edits may add a second statement.

## Comments

### @nathansl-cell · 2026-11-15 · 0 net votes

Enabling the .NET analyzer rule IDE0011 (add braces) flags brace-less `if` bodies in the editor, which catches this class of bug early. Corrections or other cases welcome below.
