Sherzy
3/17/2016 - 5:14 PM

LINQ query to comma separated string with "and" at end

LINQ query to comma separated string with "and" at end

var names = unique.Select(p => p.FirstName + " " + p.LastName).ToArray();
string result = string.Join( ", ", names.Take(names.Length - 1))
  + (names.Length <= 1 ?"":" and ") 
  + names.LastOrDefault();
// just a comma separates list
var names = t.Students.Select(p => p.CompetitionEventStudent.Student.LastName).ToArray();
string teammates = string.Join(", ", names);