Formatting a string using values from a generic list by LINQ
问题 Question Updated I have a generic list which can contains the following values: Sector 1 Sector 2 Sector 4 or the following value: All Sectors I want to format this values in a string like this: Sector 1 & 2 & 4 - or All Sectors - Currently, I have the following code to format the same. It works, but is very complicated. string retrieveSectors += sectors.Count == 0 ? string.Empty : sectors.OrderBy( y => y.Sector.Substring( y.Sector.Length - 1, 1)). GroupBy(g => g.Sector).Select( g => g.First(