Last Updated: February 25, 2016
·
336
· rudiroelofse

How to return more than one parameter from a function.

Most of us know the vintage way to return these parameters where a parameter is returned and one or more out parameters that contains the other values.

This is poor coding and un easy to read.

This can be fixed by using:

public Tuple<string,int> ReturnTwoParams()
{
Tuple<string, int> retParam =
new Tuple<string,int>("string value", 10);
return retParam;
}

private void Test()
{
Tuple<string, int> retParam = ReturnTwoParams();
string param1 = retParam.param1;
int param2 = retParam.param2;
}