Question Returning multiple values from called methods

Gerald

Member
Joined
Dec 18, 2012
Messages
6
Programming Experience
Beginner
Hello I am trying to figure out how to return multiple vaules form a single called method.

Anyone help would be greatly appreciated.
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
3,274
Location
Sydney, Australia
Programming Experience
10+
A method can only return one object. That object might contain multiple values though, e.g. an array, collection, Tuple or just have multiple properties. You can also output multiple objects from a method by using one or more parameters declared ByRef. A method with ByRef parameters may or may not also return a value. For instance, if you had to output two values that were basically equivalent then you'd use two ByRef parameters and no return value. However, if there was some logical order of precedence then you might return one and output the other using a ByRef parameter.
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
3,274
Location
Sydney, Australia
Programming Experience
10+
Oops! Forgot I was in C# land and not VB land. VB uses ByRef for any parameter that outputs a value. In C#, you use 'ref' for parameters used for input and output and 'out' for parameters used only for output.
 
Top Bottom