Supposed I have a string array like this
{
"A“,
”B",
"A,B,D",
"C"
}
Is it possible that I write a single LinQ to get the distinct values {"A","B","C","D"} into a List?
var distinctValues = myList.SelectMany(x => x.Split(',')).Distinct().ToList();
This will split each string, and then flatten them into a single list, and get the distinct elements.
If you want to get the elements in alpha order, then you can tack on a .OrderBy(x => x) right before .ToList().