Linq to xml 选择最常见的值
我需要选择 linq to xml 元素集合中最常出现的值。你是怎么做到的?
编辑,这是我尝试过的,但显然不正确;
XDocument btCheck = XDocument.Load("https://www.url.com" + postcode);
var districtCode = btCheck.Descendants("DSL_CHECKER").Elements("ADDRESS_DETAILS").Elements("ADDRESS_DETAIL").Elements("ADDRESS").Elements("DISTRICTID");
string d = (districtCode.GroupBy(z => z.Value).OrderBy(z => z.Key).Take(1)).First();
I need to select the most frequest occurrence of an value in a linq to xml collection of elements. How do you do that?
Edit, Here is what i tried but its obviously not correct;
XDocument btCheck = XDocument.Load("https://www.url.com" + postcode);
var districtCode = btCheck.Descendants("DSL_CHECKER").Elements("ADDRESS_DETAILS").Elements("ADDRESS_DETAIL").Elements("ADDRESS").Elements("DISTRICTID");
string d = (districtCode.GroupBy(z => z.Value).OrderBy(z => z.Key).Take(1)).First();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于您没有展示到目前为止您尝试过的内容,因此我只会给出一些提示,而不是完整的答案:
GroupBy
,然后是Max
。As you don't show what you tried so far, I will just give some hints instead of a full answer:
GroupBy
and thenMax
.