Topaz Filer: if you use e-mail for business, we can save you money and decrease your risk.
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
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...
 
Auto-following on Twitter
Ubuntu and XP on one “desktop”
 
    
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...
 
Outlook interop - stopping user properties appearing on Outlook message print
Seriously, why is “cut and paste” majorly newsworthy???
 
    
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...
 
Email Archiving and Email Filing - what’s the difference?
Web-based task/todo list management
 
    
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.
Recession Busting Bespoke Software
Get through the recession by investing in bespoke software to decrease costs and create commercial opportunities.
Other DN247 Network Sites
.NET 247
SQL Server Wins
Old Skool Developer
 
Copyright © AMX Software Ltd 2008-2009. Portions copyright © Matthew Baxter-Reynolds 2001-2009. All rights reserved.
Contact Us - Terms of Use - Privacy Policy - .NET 247 is a member of the DN247 Network - 4.0.30129.1734