2014/04/18

[MEMO] LINQ DISTINCT 作法

先 memo 之後再來整理


  1. string Setting = Application.StartupPath + "\\test.xml";
  2. XDocument xd = XDocument.Load(Setting);
  3. IEnumerable xe = xd.Root.Descendants("aaa").GroupBy(x => x.Value).Select(x => x.First());
  4. IEnumerable xe2 = (from node in xd.Root.Descendants("aaa")
  5. group node by node.Value into gnote
  6. select gnote.First());
  7. var xe3 = (from node in xd.Root.Descendants("aaa")
  8. group node by node.Value into gnote
  9. select new
  10. {
  11. note = gnote.First(),
  12. Count = gnote.Count()
  13. });

沒有留言:

張貼留言