Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2005
Visual Studio
Visual C#
Methods
Passing Parameters

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2005/.NET Framework 2.0

Other versions are also available for the following:
C# Programming Guide
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:

C#
// Passing by value
static void Square(int x)
{
    // code...
}
C#
// 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

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Framework Design Guidelines      Harry Pfleger   |   Edit   |   Show History

In "Framework Design Guidelines", by Cwalina and Abrams, one can read that out and ref parameters should not be used, unless necessary. This is because an architect should not expect a general audience to master this topic when working with his API.

One exception they mention is a method that is used to swap references.

Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker