Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

Passing Parameters (C# Programming Guide)

In C#, parameters can be passed either by value or by reference. Passing parameters by reference allows function members, methods, properties, indexers, operators, and constructors, to change the value of the parameters and have that change persist. To pass a parameter by reference, use the ref or out keyword. For simplicity, only the ref keyword is used in the examples in this topic. For more information about the difference between ref and out, see ref, out, and Passing Arrays Using ref and out. For example:

// Passing by value
static void Square(int x)
{
    // code...
}

// Passing by reference
static void Square(ref int x)
{
    // code...
}

This topic includes the following sections:

For more information, see the following sections in the C# Language Specification:

  • 1.6.5.1 Parameters

  • 5.1.4 Value parameters

  • 5.1.5 Reference parameters

  • 5.1.6 Output parameters

  • 10.5.1 Method parameters

Community Additions

ADD
Show:
© 2015 Microsoft