-1

I have class were I have method. now I want send two calculated values out from the method same time. how i can do that, that I can call method from main program? my program returns only first value now. Can i return somehow something like this: console.writeLine("first value" + x + "second value is:" + y? my method code:

public static double calculate(double r)
{             
    double x;
    double y;
    x = r * r;
    y = r * r * r;

    return x; // should i put something here or shuld i do somehow array?
}
juharr
  • 31,741
  • 4
  • 58
  • 93
  • You can use `Tuple` or create a custom class to hold the values you want to output. – juharr Oct 22 '15 at 17:11
  • The proper term to use when referring to returning data from method is "return". Probably because of that you could not find any similar answers - use followng search https://www.bing.com/search?q=c%23%20return%20multiple%20values%20from%20method if duplicate is not enough. – Alexei Levenkov Oct 22 '15 at 17:15

1 Answers1

2

use out parameters

double in1, in2;
double result = calculate(10, out in1, out in2);


public static double calculate(double r, out double x, out double y)
{
    x = r * r;
    y = r * r * r;

    return x;
}
Mike Corcoran
  • 14,072
  • 4
  • 37
  • 49
  • If you're going to make them both out parameters you might as well make the method return void. – juharr Oct 22 '15 at 17:23