Get max attribute value from XML using LINQ

后端 未结 2 1095
旧巷少年郎
旧巷少年郎 2021-01-18 22:47

I have the following XML file. I want to get Max(\"NR\") using LINQ. Could anyone help me to do this? I know how to do this for nodes,

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-18 23:13

    XDocument xDoc = XDocument.Load(@" your XML file path ");
    int maxNr = xDoc.Root.Elements().Max(x => (int)x.Element("NR"));
    

    After you specify the file path, you can get "NR" using the Element.

提交回复
热议问题