© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•13mo ago•
49 replies
Faker

ref keyword in C#

Hello guys, I'm just reading a bit about the
ref
ref
keyword. I understood that when we use that keyword, we tell the compiler that we want to directly work with the memory address of the variable and not a copy of it (when using it inside a method).

I have one question. I noticed that the
ref
ref
keyword is used both when writing the arguments during the method call like
callMethod(ref variable)
callMethod(ref variable)
and also during declaring the parameters of a method, we use the keyword, like
static void changeValue(ref int x)
static void changeValue(ref int x)
.

Can someone explain why ref should be used in both the arguments and parameters, why not use it either in argument or parameter
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,828Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ out vs ref keyword usage
C#CC# / help
12mo ago
Confusing code with keyword ref
C#CC# / help
2y ago
✅ namespace and using keyword in C#
C#CC# / help
10mo ago
✅ using keyword for resource management in C#
C#CC# / help
12mo ago