-2

I need Count() of "ITEM_STATUS=10" , Please help me in this.Please find the below picture..Image

MSanika
  • 1,311
  • 5
  • 13
  • 21

1 Answers1

1

Stack Overflow questions should show a minimal amount of effort to solve the problem. This is not a free code service.

Nonetheless, the following should produce the result you are requesting:

var count = e.Descendants("ITEM_STATUS")
             .Where(el => "10".Equals((string)el))
             .Count();
JLRishe
  • 99,490
  • 19
  • 131
  • 169
  • 1
    Why `"10".Equals((string)el)` instead of `(int)el == 10`, or `(string)el == "10"`? This syntax looks kind of weird. – MarcinJuraszek Feb 09 '14 at 00:17
  • 1
    @MarcinJuraszek `(int)el == 10` will throw a `FormatException` if any of the `ITEM_STATUS` elements in the document contains a non-integer value, so that's worth avoiding unless you're _absolutely sure_ that every `ITEM_STATUS` will contain an integer value (or if you want an exception to happen if any of them is a non-integer). Avoiding `==` for strings is a personal preference, and bit of a carry-over from Java and C, but it's worth noting that under [certain circumstances](http://stackoverflow.com/a/15090520/1945651), `==` can produce `false` for equivalent strings in C#. (continued...) – JLRishe Feb 09 '14 at 04:36
  • 1
    ... Lastly, using `LITERAL.Equals(VARIABLE)` instead of `VARIABLE.Equals(LITERAL)` is a safeguard against a NullReferenceException. Probably not needed here, but it doesn't hurt to use a cautious, consistent style. – JLRishe Feb 09 '14 at 04:37