linq分组查询

string[] arrStr = { ".com", "www.baidu.com", "www.qq.com", "www.bing.cn", "www.avc.net","www.vvv.cn","www.bbb.net" };
           

//定义查询规则

var addressG = from gg in arrStr
                           where gg.LastIndexOf(".") != -1
                           group gg by gg.Substring(gg.LastIndexOf("."));
           

//执行查询

//迭代每一组

foreach (var grp in addressG)
            {

//迭代每组里的值
                foreach (var item in grp)
                {
                    Console.WriteLine(grp.Key+":"+item);
                }
            }

你可能感兴趣的:(LINQ)