C# Feature - ref locals
Overview
Section titled βOverviewβRef locals let a local variable alias another storage location, which avoids copying and can allow in-place updates.
Introduced In
Section titled βIntroduced InβC# 7.0 (2017)
var item = values[0];item++;ref int item = ref values[0];item++;Gotchas & Best Practices
Section titled βGotchas & Best Practicesβ- Use ref locals only when aliasing is intentional and clearly beneficial.
- Overuse can make code harder to reason about than ordinary value copies.