ref (C# reference)
You use the ref keyword in the following contexts:
- In a method signature and in a method call, to pass an argument to a method by reference.
- In a method signature, to return a value to the caller by reference. For more information, see
ref return. - In a declaration of a local variable, to declare a reference variable section of the Declaration statements article.
- As the part of a conditional ref expression or a ref assignment operator.
- In a
structdeclaration, to declare aref struct. For more information, see therefstructure types article. - In a
ref structdefinition, to declare areffield. For more information, see thereffields section of therefstructure types article.
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
.NET feedback
The .NET documentation is open source. Provide feedback here.
Feedback
Submit and view feedback for