© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
8 replies
Moods

with or without ref

so i learned that in c#(or most oop languages) when you create a method that takes an object as a parameter, and you call said method and pass an object of the same type as an argument, it passes the reference to the caller. so if you were to alter any properties of the object parameter in the method, it affects the object that was used as a parameter

something like

void ChangeName(Person p) {
    p.Name = "Alice";
}

Person person = new Person();
person.Name = "Bob";
ChangeName(person);
void ChangeName(Person p) {
    p.Name = "Alice";
}

Person person = new Person();
person.Name = "Bob";
ChangeName(person);


i assume that after the last statement person's Name property is now "Alice".

i was reading up the docs and it mentioned you would use
ref
ref
before an object parameter if you wanted to alter the original object argument and I'm confused cus isnt this how objects already worked like..?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Confusing code with keyword ref
C#CC# / help
2y ago
Set indexer inside a ref struct without assigning variable?
C#CC# / help
3w ago
✅ Is managed pointer (ref) or raw pointer (void*) null?
C#CC# / help
4y ago
SqlException without stopping or catching
C#CC# / help
2y ago