I want to get the highest attribute “ID” from my XML file.
My code:
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();
When in my XML file is one of Invoice code works, but when is for example 2 invoice I have an error:
At least one object must implement IComparable.
Try casting
f.Attributes("ID")into anintif it’s numeric or astringif it’s alphanumeric like this: