.NETGURU
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.
Post a new message to this list...

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...
 
    
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...
 
    
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...
 
    
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...
 
    
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...
 
    
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...
 
    
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...
 
 
System.Data.DataSet




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification