Can a function return two values?

DeltaWolf7

Well-known member
Joined
Jan 21, 2006
Messages
47
Programming Experience
Beginner
Hi,
I am a newbie to vb.net 2005. I have creayed a function but I want to return two values. One which is a string and the other which is an integer.

Is it possible to return these two values and use them separately?

Thank you
 
A function can only return a single object. If you want to get more than one value from a method you have three options.

1. Have your function return either an array or a collection that contains each of the objects you want.
2. Define your own type that has properties corresponding to the values you want and have your function return an instance of that type.
3. Pass one or more arguments to your method ByRef and set them within the method.
 
4. setup an enumeration for bitwise operations and return different combinations in a single value
 
JohnH said:
4. setup an enumeration for bitwise operations and return different combinations in a single value
Nice one. May not work in the current circumstance with the String and Integer, although it may still be suitable, and certainly would in many others.
 
Many thanks for you speedy answers.

One question though. How do I return the entrie array?
I know I can return parts like
return myarray(1)

but how do i return the whole thing?

Thank you
 
set the function to return what you want to return, if you want it to return string array for example:
VB.NET:
Function myfunction() As String()
  'SomeStrings string array object is defined
  return SomeStrings
End Function
 
Back
Top