【发布时间】:2011-07-16 10:19:32
【问题描述】:
我正在尝试解析以下 xml 文件:http://reports.ieso.ca/public/DispUnconsHOEP/PUB_DispUnconsHOEP_20110714.xml
我的目标是获得最大的price 及其关联的hour 和最小的price 及其关联的hour。
我应用的逻辑如下:
解析 Xml 文件并将其传递给包含 hour 和 price 对的 IList
根据price 以降序对IList 进行排序
检索 IList 中的第一个值作为最大值,而检索 IList 中的最后一个值作为最小值。
我的代码是:
XNamespace nsPriceHr = "http://www.theIMO.com/schema";
XDocument xDocument =
XDocument.Load("http://reports.ieso.ca/public/DispUnconsHOEP/PUB_DispUnconsHOEP_20110714.xml");
XElement xEl1 = xDocument.Element(nsPriceHr + "IMODocument");
XElement xEl2 = xEl1.Element(nsPriceHr + "IMODocBody");
XElement xEl3 = xEl2.Element(nsPriceHr + "HOEPs");
var data = (from x in xEl3.Descendants(nsPriceHr + "HOEP")
orderby x.Element(nsPriceHr + "Price").Value descending
select new HourPrice
{
Hour = x.Element(nsPriceHr + "Hour").Value,
Price = x.Element(nsPriceHr + "Price").Value
})
.ToList();
我的问题是:列表没有按预期排序。采用Hour 和Price 这两个值的 HourPrice 对象的两个数据成员都是字符串。
我正在使用 C#、.NET 3.5 SP1 并使用 winforms。任何帮助表示赞赏
【问题讨论】:
标签: c# .net winforms sorting ilist