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()).ToList().Aggregate(
retrieveSectors,
(current, y) =>
(current == retrieveSectors
? current +
y.Sector
: current + " & " +
y.Sector.
Substring(
y.Sector.
Length - 1, 1))) + " - "
In the above code, the variable sector is the generic list. Can someone help me to attain the results in a simplified way.? Or may be modify the above code so that it is more understandable.
Any help appreciated. Thanks