473,387 Members | 1,844 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Return by references or value

Will the dataset below be returned by value or reference?
Public Shared Function getDS() As DataSet
Dim ds As New DataSet
'... do something
Return ds
End Function
Nov 21 '05 #1
2 1662
Arne,
The "reference" to the data set, will be returned "by value". In other words
a copy of the reference to a single object on the heap will be returned.

DataSet is a Reference Type so variables of type DataSet always hold a
reference to the actual DataSet object. A single copy of the actual DataSet
object exists on the heap.

Where as Integer is a Value Type, so variables of type Integer always hold
the value of the actual Integer 'value'. Multiple copies of the Integer
value exists in each variable (either on the stack or in a Reference Type on
the heap).

Remember ByVal & ByRef are how parameters are passed, Reference Type & Value
Type are how variables are stored. If you pass a Reference Type ByVal a copy
of the reference to a single object on the heap is passed. If you pass a
Value Type ByVal a copy of the 'value' is passed. If you pass a Reference
Type ByRef, then a reference to the original variable is passed, the
original variable still contains a single reference to the object on the
heap. Likewise if you pass a Value Type ByRef, then a reference to the
original variable is passed.

Which allows the called routine of ByRef parameters to modify the what the
original variable contains/references...

Hope this helps
Jay
"Arne" <Ar**@discussions.microsoft.com> wrote in message
news:CA**********************************@microsof t.com...
| Will the dataset below be returned by value or reference?
| Public Shared Function getDS() As DataSet
| Dim ds As New DataSet
| '... do something
| Return ds
| End Function
Nov 21 '05 #2
What would by reference, or by value mean in this context? This sort of idea
just doesn't apply when returning variables. How would that work?

That only applies to parameters of methods.

There is only one way you can return an object from a method. And that is to
return a reference to that object. But the word 'reference' here is not
related to the concept of passing parameters 'by reference'.

"Arne" <Ar**@discussions.microsoft.com> wrote in message
news:CA**********************************@microsof t.com...
Will the dataset below be returned by value or reference?
Public Shared Function getDS() As DataSet
Dim ds As New DataSet
'... do something
Return ds
End Function

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: John Ramsden | last post by:
.... when the id 'junk' doesn't exist anywhere in the document, instead of returning 'object'?! I am using Javascript for a drop-down menu, slightly adapted from one by Angus Turnbull (see...
14
by: Gama Franco | last post by:
Hi, I'm designing an interface for a shared library, and I would like to know if there is a standard about how to return an object to the user. I will use exceptions to report errors, so there...
29
by: pmatos | last post by:
Hi all, Sometimes I have a function which creates an object and returns it. Some are sets, other vectors but that's not very important. In these cases I do something like this: vector<int> *...
5
by: Neal Coombes | last post by:
Posted to comp.lang.c++.moderated with little response. Hoping for better from the unmoderated groups: -------- Original Message -------- Subject: Return appropriately by value, (smart)...
2
by: Arne | last post by:
How do I return a references to an object from a function? static ArrayList getItemFile(string destdir){...} Does the above code return the whole Arraylist on the stack or does it return a...
40
by: Mark P | last post by:
I'm implementing an algorithm and the computational flow is a somewhat deep. That is, fcn A makes many calls to fcn B which makes many calls to fcn C, and so on. The return value of the outermost...
32
by: Axel Bock | last post by:
Hi all, I am trying to get my head around what happens if I return a class object from a function. It seems C++ (MinGW) does not invoke the copy constructor if I do something like this: ...
0
by: terminator(jam) | last post by:
Since delaration of C++ the r/l-valueness of objects has been source of confusion there are some actions that can perform on lvalues but not on rvalues , especifically on initrinsic types .BTW the...
10
by: flopbucket | last post by:
Hi, Is this legal? std::string foo() { std::string xyz = "FOO"; return xyz; }
68
by: Jim Langston | last post by:
I remember there was a thread a while back that was talking about using the return value of a function as a reference where I had thought the reference would become invalidated because it was a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.