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)
Before
Section titled “Before”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.