我想从我的XML文件中获取最高属性"ID".
我的代码:
var doc = XElement.Load("invoices.xml");
var q = (from f in doc.Element("ListOfInvoices").Elements("Invoice")
orderby f.Attributes("ID") descending
select f.Attribute("ID")).FirstOrDefault();
Run Code Online (Sandbox Code Playgroud)
在我的XML文件中,其中一个发票代码有效,但是当例如2发票时,我有一个错误:
至少有一个对象必须实现IComparable.
尝试转换f.Attributes("ID")
成int
if if的数字或string
if if它的字母数字如下:
var q = (from f in doc.Element("ListOfInvoices").Elements("Invoice")
orderby (int)f.Attribute("ID") descending
select f.Attribute("ID")).FirstOrDefault();
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1434 次 |
最近记录: |