Multimobile Development: Building Applications for any Smartphone
What's the best practice to pass dataset object?
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.performance.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

Rahul Agarwal
GOOD ANSWER
Hi

I am looking for best practice on passing dataset object around, should it
be passed by reference or by value. What gives the best performance, how
does it works internally when you pass by value?

Please advice, thanks
Rahul

Reply to this message...
Vote that this is a GOOD answer... (3 votes from other users already)
 
 
    
anonymous@discussions.microsoft.com
DataSet class is a reference type. It does not matter if
you pass a refence by reference or by value, it is still
passed by reference.
To verify this, dissamble an assembly that contains 2
methods: one has a dataset passed by value and another has
a dataset passed by reference.
Best regards,
Aleksey Nudelman
http://csharpcomputing.com

[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer...
 
Really good experience at the Apple Store
MonoDroid – looking *awesome*
 
    
Jon Skeet [C# MVP] (VIP)
<Click here to reveal e-mail address> wrote:
[Original message clipped]

That's not true. There's a big difference between passing a reference
by value and passing a reference expression by reference.

See http://www.pobox.com/~skeet/csharp/parameters.html

[Original message clipped]

And you'll see that they're different.

--
Jon Skeet - <Click here to reveal e-mail address>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Reply to this message...
Vote that this is a GOOD answer...
 
 
    
MFRASER
Ok. I read the link, very good document.

but is this what the article is saying?

The article states the following:

This difference is absolutely crucial to understanding parameter passing
in C#, and is why I believe it is highly confusing to say that objects
are passed by reference by default instead of the correct
statement that object references are passed by value by default.

So if I do the following

private void Myfunction(Myobject a)
this is passing the value of the object?

and

private void Myfunction(ref MyObject a)
this is passing the reference of the object?

"Jon Skeet [C# MVP]" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer...
 
First volume of Multimobile Development nearly ready to go to press
A mention on Developing for the iPhone and Android: The pros and cons
 
    
Jon Skeet [C# MVP] (VIP)
MFRASER <Click here to reveal e-mail address> wrote:
[Original message clipped]

No, it's passing a reference. The value of the variable, expression,
whatever, that you use when calling the method - that value is a
reference.

[Original message clipped]

That's passing the reference *by* reference.

(Assuming MyObject is a class, not a struct.)

--
Jon Skeet - <Click here to reveal e-mail address>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Reply to this message...
Vote that this is a GOOD answer...
 
 
    
Scott M.
If you pass a reference type ByRef, you will be passing a pointer to the
first pointer to the object. Sort of like A points to B which is pointing
at the oject C.

If you pass a reference type ByVal, you will be passing a "copy of the
pointer to the object". Sort of like A and B are identical and then each
point at the object C.

The difference is that in scenario 1 above, A points at whatever B is
pointing to, but in scenario 2 above, A and B are pointing individually to
the same other thing.

Theoretically, in scenario 2 above, B could be re-pointed to something else
without affecting A. But in the first case, if B is changed to point at
something else and changes with it.

"Jon Skeet [C# MVP]" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer...
 
 
    
Jon Skeet [C# MVP] (VIP)
Rahul Agarwal <Click here to reveal e-mail address> wrote:
[Original message clipped]

See http://www.pobox.com/~skeet/csharp/parameters.html

--
Jon Skeet - <Click here to reveal e-mail address>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Reply to this message...
Vote that this is a GOOD answer...
 
 
 
System.Data.DataSet




Ad
BootFX
Reliable and powerful .NET application framework.
iOS, Android and Windows Phone Development Training and Consultancy
Hosted by RackSRV Communications
 
Multimobile Development: Building Applications for any Smartphone
Copyright © AMX Software Ltd 2008-2010. Portions copyright © Matthew Baxter-Reynolds 2001-2010. All rights reserved.
Contact Us - Terms of Use - Privacy Policy - 4.0.30129.1734