2014/04/18

[MEMO] LINQ DISTINCT 作法

先 memo 之後再來整理


 
    string Setting = Application.StartupPath + "\\test.xml";
    XDocument xd = XDocument.Load(Setting);

    IEnumerable xe = xd.Root.Descendants("aaa").GroupBy(x => x.Value).Select(x => x.First());

    IEnumerable xe2 = (from node in xd.Root.Descendants("aaa")
                                group node by node.Value into gnote
                                select gnote.First());

    var xe3 = (from node in xd.Root.Descendants("aaa")
               group node by node.Value into gnote
               select new
               {
                   note = gnote.First(),
                   Count = gnote.Count()
               });


沒有留言:

張貼留言