Yes, the out keyword:
public void ReturnManyInts(out int int1, out int int2, out int int3) { int1 = 10; int2 = 20; int3 = 30; }
then name it like this:
int i1, i2, i3; ReturnManyInts(out i1, out i2, out i3); Console.WriteLine(i1); Console.WriteLine(i2); Console.WriteLine(i3);
which outputs:
10 20 30
EDIT:
I see that many posts suggest creating your own class for you. This is optional since .net provides you with a class to do what they say already. Class Tuple .
public Tuple<int, string, char> ReturnMany() { return new Tuple<int, string, char>(1, "some string", 'B'); }
then you can get it like this:
var myTuple = ReturnMany(); myTuple.Item1 ... myTuple.Item2 ...
There are general overloads, so you can have up to 8 unique types in your tuple.
Joel
source share