Today I faced one question that which are the possible ways to return more than one values in function in C#
1 is returning object but what are other possible ways of doing it
Regards
Today I faced one question that which are the possible ways to return more than one values in function in C#
1 is returning object but what are other possible ways of doing it
Regards
You can use output parameters:
public void Foo(out int bar, out string goo)
{
bar = 1;
goo = "moo";
}
And use it like this:
int a;
string b;
Foo(out a, out b);
You can use a Tuple to return more than one value. Keep in mind, they can get out of hand pretty quick.
public Tuple<string, int> Foo()
{
return Tuple.Create("Bar",1);
}
Tupples can be spun up with multiple values.
Tuple<int,string,int,int,string>
They can get messy quick :)
Good luck