Pass by Reference

In this lesson, we'll discuss how to use pass by reference to pass parameters to methods in C#.

Introduction

From the documentation :

Passing by reference enables function

  • members
  • methods
  • properties
  • indexers
  • operators
  • constructors

to change the value of the parameters and have that change persist in the calling environment. To pass a parameter by reference, use the ref keyword.

Syntax

Here’s the syntax used to pass a value by reference:

Get hands-on with 1400+ tech skills courses.