Passing Reference types by value in C#

Posted by Ajit on Stack Overflow See other posts from Stack Overflow or by Ajit
Published on 2008-11-05T08:28:30Z Indexed on 2010/04/08 10:23 UTC
Read the original article Hit count: 267

Filed under:
|
|

I want to pass a reference type by value to a method in C#. Is there a way to do it.

In C++, I could always rely on the copy constructor to come into play if I wanted to pass by Value. Is there any way in C# except: 1. Explicitly creating a new object 2. Implementing IClonable and then calling Clone method.

Here's a small example:

Let's take a class A in C++ which implements a copy constructor.

A method func1(Class a), I can call it by saying func1(objA) (Automatically creates a copy)

Does anything similar exist in C#. By the way, I'm using Visual Studio 2005.

© Stack Overflow or respective owner

Related posts about reference

Related posts about value