473,788 Members | 3,030 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1683
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**@discussio ns.microsoft.co m> wrote in message
news:CA******** *************** ***********@mic rosoft.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**@discussio ns.microsoft.co m> wrote in message
news:CA******** *************** ***********@mic rosoft.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
46575
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 http://javascript.internet.com and http://gusnz.cjb.net, not that this is probably relevant but it deserves a plug ;-), on Internet Explorer v6.0.2800.1106. I need this feature of getElementById(), or an equivalent one (using sound and standard...
14
2046
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 are at least four ways to do it. For example if we have a method named M, that receives a reference to parameter p and returns object o.
29
2253
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> * f() { vector<int> * v = new vector<int>; return v; }
5
3047
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) pointer, or reference Date: 27 Aug 2005 15:13:23 -0400 From: Neal Coombes <nealc@trdlnk.com> Organization: Aioe.org NNTP Server To: (Usenet) Newsgroups: comp.lang.c++.moderated
2
13984
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 reference?
40
3160
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 fcn is a boolean and there are certain places within the inner functions where it may become apparent that the return value is false. In this case I'd like to halt the computation immediately and return false. My current approach is to have...
32
2218
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: SomeObj foo() { SomeObj X;
0
1313
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 programmer is not capable of defining special interface for classes based on the r/l-valueness of the object(the way we do for const/volatile).Move proposal - about Hot(rvalue) refernce - has been an attempt to get that different behavior at...
10
4013
by: flopbucket | last post by:
Hi, Is this legal? std::string foo() { std::string xyz = "FOO"; return xyz; }
68
4655
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 temporary but it was stated that it would not. This has come up in an irc channel but I can not find the original thread, nor can I get any code to work. Foo& Bar( int Val ) { return Foo( Val ); }
0
10363
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10172
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6749
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5535
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.