DistinctCsv
Returns a distinctive comma-separated list.
Source
/// <summary> Returns a distinctive comma-separated list.</summary>
public static string DistinctCsv<T>(this IList<T> list)
{
if (list == null || list.Count == 0)
{
return ""; // nothing to work with
}
else if (list.Count == 1)
{
return list.ToString(); // no need for distinct or comma joining
}
return string.Join(",", list.Distinct()).ToString();
}
Example
private string GetDistinctSetNames()
{
List<string> sList = new List<string>();
foreach (SelectedScenario s in SelectedScenarios)
{
sList.Add(s.Scenario.EvalFactorSet.Name);
}
return sList.DistinctCsv(); // culls duplicates and makes CSV
}