getting multiple values returned from a method

  • Thread starter Thread starter Homer Simpson
  • Start date Start date
H

Homer Simpson

Hi All,

I'm trying to write a method where I pass three arguments and the method
returns six values. All the values will be doubles. First, is it possible to
get multiple values returned by a method? Second, how do I do it? I know how
to write the method, pass arguments to it and get a single value returned
but how do I pass multiple values back? Last, how do I reference the various
values returned? I assume there is some array used here. Any examples are
greatly appreciated.

Thanks,
Scott
 
I'm trying to write a method where I pass three arguments and the method
returns six values. All the values will be doubles. First, is it possible
to get multiple values returned by a method? Second, how do I do it? I
know how to write the method, pass arguments to it and get a single value
returned but how do I pass multiple values back? Last, how do I reference
the various values returned? I assume there is some array used here. Any
examples are greatly appreciated.

Thanks,
Scott
Well returning an array as other have said or....

void Test(out double d1, out double d2, out double d3)
{
d1 = 1.1;
d2 = 2.2;
d3 = 3.3;
}

void UseTest()
{
double d1;
double d2;
double d3;

Test(out d1, out d2, out d3);
}
 
In addition to the other excellent suggestions, you could define a structure
or class that would hold your values, then return an instance of the
structure or class.
 
Back
Top