pass an object by value.
-
any one knows how to pass an object by value instead of reference in C#?
-
any one knows how to pass an object by value instead of reference in C#?
Step 1) Ensure it's a value. Step 2) Pass it.
-
any one knows how to pass an object by value instead of reference in C#?
Hi, that is not possible. Not sure why you think you want that. Maybe what you need is a clone, i.e. a second object that is an exact copy of the original, so changing it would not change the original. I very seldom need that though. I suggest you explain the situation. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
-
Hi, that is not possible. Not sure why you think you want that. Maybe what you need is a clone, i.e. a second object that is an exact copy of the original, so changing it would not change the original. I very seldom need that though. I suggest you explain the situation. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
thanx, i just wanted to know whether it is possible or not , cloning means before sending we create a copy of the object and send it to the method. hmmm.. thanx.
-
thanx, i just wanted to know whether it is possible or not , cloning means before sending we create a copy of the object and send it to the method. hmmm.. thanx.
Refer http://www.c-sharpcorner.com/UploadFile/rmcochran/chsarp\_memory401152006094206AM/chsarp\_memory4.aspx for an excellent explanation on clone.
Praveen Raghuvanshi Software Engineer, India.
-
thanx, i just wanted to know whether it is possible or not , cloning means before sending we create a copy of the object and send it to the method. hmmm.. thanx.
prasadbuddhika wrote:
cloning means before sending we create a copy of the object and send it to the method.
Which is also passed by reference...
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009... -
any one knows how to pass an object by value instead of reference in C#?
All parameters are passed by value in C#...you have to use additional modifiers in order for them to be passed by reference (use either "ref" or "out" keywords). http://msdn.microsoft.com/en-us/library/0f66670z(VS.71).aspx[^]
-
All parameters are passed by value in C#...you have to use additional modifiers in order for them to be passed by reference (use either "ref" or "out" keywords). http://msdn.microsoft.com/en-us/library/0f66670z(VS.71).aspx[^]
But most of those values are references.
-
All parameters are passed by value in C#...you have to use additional modifiers in order for them to be passed by reference (use either "ref" or "out" keywords). http://msdn.microsoft.com/en-us/library/0f66670z(VS.71).aspx[^]
Everything that is passed is a value in the truest sense. However that value is (most) often a reference to the object rather than the 'value' itself. The only way to do what the op wants is to create a new object (therefore a new reference) and copy the values the object holds. Where the object's values are also references, new copies of those also need to be created. This needs to be done recursively until all object references have been recreated. This is known as deep cloning and, as you can see, can be quite an involved and complex task which is why there is no built in
Clone
method in the framework. The closest we have isICloneable
which has (of course as it's an interface) to be implemented by the creator of the class.Dave
If this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)