c#xml显示最高值

c#xml显示最高值,c#,xml,linq,C#,Xml,Linq,我完全没有想法,而且我的C#/LINQ/XML技能仍然很弱。也许有人能帮我完成一个相对简单的任务,我不想写一个完整的程序: 我需要在XML数据库中获得最高的客户ID,该数据库看起来有点像: <xml> <customers> <customer> <customerid>a00001</customerid> <name>this</name> </custome

我完全没有想法,而且我的C#/LINQ/XML技能仍然很弱。也许有人能帮我完成一个相对简单的任务,我不想写一个完整的程序:

我需要在XML数据库中获得最高的客户ID,该数据库看起来有点像:

<xml>
  <customers>
    <customer>
      <customerid>a00001</customerid>
      <name>this</name>
    </customer>
    <customer>
      <customerid>a00031</customerid>
      <name>that</name>
    </customer>

有些东西不起作用了。任何人都知道我不必将所有数据放在一个数组中,对该数组进行排序并给出第一个元素(因为这是我剩下的唯一想法,但似乎有点太多)

或者使用linq/xpath的组合更简洁

int id = readme.XPathSelectElements("/customers/customer/customerid").Max(cid => int.Parse(cid.Value.Substring(1)));

或者更简洁地使用linq/xpath组合

int id = readme.XPathSelectElements("/customers/customer/customerid").Max(cid => int.Parse(cid.Value.Substring(1)));

但是为什么不直接使用LINQ和查询XML呢?请参阅本文,但为什么不直接使用LINQ和查询XML?在这种情况下,请参阅本文。子字符串(2)会更好,因为随着客户数量的增加,customerid可能会得到更多的数字。为什么从2开始不是1?你们是最好的!在这种情况下,子字符串(2)会更好,因为随着客户数量的增加,customerid可能会得到更多的数字。为什么从2开始不是1?你们是最好的!
int id = readme.XPathSelectElements("/customers/customer/customerid").Max(cid => int.Parse(cid.Value.Substring(1)));