I want to return multiple parameter from a method in c#.I just wanted to know which one is better out or Tuple?
static void Split (string name, out string firstNames, out string lastName)
{
int i = name.LastIndexOf (' ');
firstNames = name.Substring (0, i);
lastName = name.Substring (i + 1);
}
static Tuple<string,string> Split (string name)
{
//TODO
}
There is usually a (value) class hiding somewhere if you need to return more than one value from a method. How about a value class with the
Split()method as ctor:Instead of
just do
and access the first and last name via
n.FirstNameandn.LastName.