I need some help with the following:
I have a list where all the duplicate entries need to be removed from and I cant seem to get the right linq query. now the list itself contains a string and a list of strings as parameters.
see the code snippets:
the list is created from this class
public class SD
{
public string From { get; set; }
public List<string> To { get; set; }
}
the input of the list may look like this:
var unsortedList = new List<SD>
{
new SD {From = "a", To = new List<string>{ "b" } },
new SD {From = "b", To = new List<string>{ "a" } },
new SD {From = "a", To = new List<string>{ "b", "c" } },
new SD {From = "a", To = new List<string>{ "b" } },
new SD {From = "a", To = new List<string>{ "c" } },
};
Before the To in the class was a list and just was a string the below code was working perfect. It would return 4 entries as entry 1 and 4 are equal (and off course the 3rd entry would only have one string).
var sortedList = unsortedList.GroupBy(x => new { x.From, x.To }).Select(group => group.First()).ToList();
I've been playing around with orderby, group and hashsets but none seems to work.