I've looked at several answers to similar questions, but none of them solve my problem. All I need to do is get distinct values from a LINQ query (that queries a XML file) and put them into a list. Here is what I have tried:
var XmlData = XDocument.Load("PathToFile"); List<string> XmlItems = new List<string>(); var XQuery = from m in XmlData.Root.Elements() where m.Attribute("Category").Value.ToString().Equals("TheCategory") select (m.Attribute("TheAttribute").Value).Distinct().ToString(); XmlItems.AddRange(XQuery); foreach (var item in XmlItems) { ComboBoxTeams.Items.Add(item); } The Distinct() function call is not working. I'm unfamiliar with how to get distinct values from a LINQ query. Any suggestions?
No comments:
Post a Comment