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.
- 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. - In a generic type declaration to specify that a type parameter
allows ref structtypes.
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.
Feedback
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see: https://aka.ms/ContentUserFeedback.
Submit and view feedback for