locked
LINQ to retrieve XML <Sample></Sample>attribute RRS feed

  • Question

  • User527076549 posted

    Hi,

    Below is code, i want to select attribute with highest value. Can anyone suggest me how to do it

    <Samples>
    <Sample Id="1">one</Sample>
    <Sample Id="2">two</Sample>
    <Sample Id="3">three</Sample>
    .
    .
    .
    .
    </Samples>

    i want to retrieve the greatest Id value.Example in above code i want the value Id=3 to be selected. I tried 

    var result = root.Element("Samples").Elements("Sample").OrderByDescending (x =>(int)x.Attribute("Id"));

    it gives in Desc order again i have to parse the result. SO can anyone tell me if it can be done in single line

    Thanks in advance.

    Thursday, October 1, 2015 2:35 PM

Answers

All replies