Chapter 13. Improving efficiency with more pass by reference

This chapter covers
  • Aliasing variables with the ref keyword
  • Returning variables by reference with ref returns
  • Efficient argument passing with in parameters
  • Preventing data changes with read-only ref returns, read-only ref locals, and read-only struct declarations
  • Extension methods with in or ref targets
  • Ref-like structs and Span<T>

When C# 7.0 came out, it had a couple of features that struck me as slightly odd: ref local variables and ref returns. I was slightly skeptical about how many developers would need them, as they seemed to be targeted situations involving large value types, which are rare. My expectation was that only near-real-time services and games ...

Get C# in Depth, Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.