|
-
May 3rd, 2005, 07:12 AM
#1
Thread Starter
Lively Member
Return values from a function
I want to return four values (more than one) from a function to its caller.
Four values are of four datatypes(int, long, double, string).
I just know how to return one value from a function. But how can I return more than one ?
Is it possible ?
plz, Give an example.
--Rajib
-
May 3rd, 2005, 07:35 AM
#2
Re: Return values from a function
technically a function is only meant to return one value, so you should create a class or structure that will hold your four values.
You could use the out keyword, but it's not a good solution
-
May 3rd, 2005, 07:56 AM
#3
Thread Starter
Lively Member
Re: Return values from a function
Thanks for your help.
But I have found that it is easily solved by Reference passing.
---Rajib
-
May 3rd, 2005, 08:15 AM
#4
Re: Return values from a function
Something to bear in mind an argument passed by ref must be first initialised. An out does not have to be initialised.
-
May 3rd, 2005, 11:56 PM
#5
Re: Return values from a function
Can you tell me more about the out keyword?
-
May 4th, 2005, 03:03 AM
#6
Re: Return values from a function
-
May 4th, 2005, 09:08 AM
#7
Re: Return values from a function
Ah, so the out keyword is quite like those from SPs. Yet another feature I wish VB.NET had.
-
May 4th, 2005, 09:09 AM
#8
Re: Return values from a function
ref exists in VB.NET. When you pass an argument to a function, you can do it ByVal or ByRef.
-
May 4th, 2005, 11:28 AM
#9
Addicted Member
Re: Return values from a function
An interesting thing with C# is that using out, ref or neither of them for a given function parameter defines different function signatures. This allows the overloading of a function in this way :
Code:
void testfunction(int iVal)
{
}
void testfunction(ref int iVal)
{
}
void testfunction(out int iVal)
{
}
All is well if used only in C#, but you cannot use this function in VB through a compiled assembly because it is ambiguious in VB because in VB you don't tell the compiler that you want to send your function parameter ByVal or ByRef.
There are no stupid questions, but a whole bunch of dumb sayings !
Save time on database code, try DataLG !
-
May 5th, 2005, 03:01 AM
#10
Re: Return values from a function
Code:
//this is a valid overload
void testfunction(int iVal){}
void testfunction(ref int iVal){}
//so is this
void testfunction(int iVal){}
void testfunction(out int iVal){}
//this is not a valid overload
void testfunction(ref iVal){}
void testfunction(out int iVal){}
-
May 5th, 2005, 09:17 AM
#11
Addicted Member
Re: Return values from a function
My bad, I assumed that it would be valid too, I never tried to mix out and ref before...
There are no stupid questions, but a whole bunch of dumb sayings !
Save time on database code, try DataLG !
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|