public Person[] ParseNames(params string[] list)
        {
            if (list != null)
            {
                List<Person> people = new List<Person>();

                foreach (string item in list)
                {
                    // Break it down to first name and last name
                    string[] names = item.Split(',');

                    if (names.Length > 0)
                    {
                        Person person = new Person()
                        {
                            LastName = names[0].Trim()
                        };

                        // The name contains more than 2 parts, let's just get the second part and ignore the rest
                        if (names.Length > 1)
                        {
                            person.FirstName = names[1].Trim();
                        }

                        // Only add to the list for sorting if the last name and first name exist
                        if (!string.IsNullOrEmpty(person.LastName) || !string.IsNullOrEmpty(person.FirstName))
                        {
                            people.Add(person);
                        }
                    }
                }
                return people.ToArray();
            }
            return null;
        }
예제 #2
0
 public string FormatPerson(Person person)
 {
     return string.Format("{0}, {1}", person.LastName, person.FirstName);
 }