© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•9mo ago•
87 replies
CoreDump

✅ Function argument class reference / clone (best practice(s))

Hello,

I'm a total newbie in
C#
C#
. I mostly come from
Rust
Rust
and
C
C
/
C++
C++
.

When writing a function what are the best practices to tell the caller (I'm mostly interested with a
class
class
(since they are reference types)):
- The parameter will be taken (owned by the
class
class
from the called method)
- You can use it after since the argument will be cloned (is it a good practice ? is
ICloneable
ICloneable
a good practice ?)
- The argument will be modified after calling the method / function (is
ref
ref
the standard ?)

Does it make sense to
Clone()
Clone()
in
C#
C#
to make sure a value lives on it's own ? Is it commonly used ?

I read the documentation (https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/method-parameters) and it clearly says about reference types (such as
class
class
):
The called method can't reassign the instance in the calling method. However, the called method can use the copy of the reference to access the instance members. If the called method changes an instance member, the calling method also sees those changes since it references the same instance.

How do you know in which case you are when calling a method / function ? (I hope my questions make sense, I apologize if it doesn't 🙏 -> I don't want to modify a value / variable and have unintended impact (same reference) on another variable)

Thank you very much in advance for any help
Method parameters and modifiers - C# reference
Parameter modifiers enable pass-by-reference semantics, with distinctions for read-only, and
out
out
parameters. The
params
params
modifier allows optional arguments.
Method parameters and modifiers - C# reference
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements
Next page

Similar Threads

Best practice for class constructors?
C#CC# / help
2y ago
✅ Class instance reference
C#CC# / help
11mo ago
✅ Best practice when using HttpClient in a class
C#CC# / help
3y ago
❔ Tests best practice
C#CC# / help
3y ago