Typically, a class (value) is hidden if you need to return more than one value from a method. How about a class of values ββusing the Split()
method as ctor:
public class Name { public Name(string name) { int i = name.LastIndexOf (' '); FirstNames = name.Substring (0, i); LastName = name.Substring (i + 1); } public string FirstName {get; private set;} public string LastName {get; private set;} }
Instead
Split(name, out string firstName, out string lastName);
simply
Name n = new Name(name);
and access the first and last name through n.FirstName
and n.LastName
.
source share