querying nested array elements in C#
Posted
by the berserker
on Stack Overflow
See other posts from Stack Overflow
or by the berserker
Published on 2010-04-09T09:29:02Z
Indexed on
2010/04/09
9:33 UTC
Read the original article
Hit count: 385
I have following object structure, deseralized from XML (WS):
<ns2:Category>
<ns2:CategoryId>800003</ns2:CategoryId>
<ns2:CategoryName>Name1</ns2:CategoryName>
<ns2:Categories>
<ns2:Category>
<ns2:CategoryId>800008</ns2:CategoryId>
<ns2:CategoryName>Name2</ns2:CategoryName>
<ns2:Categories>
<ns2:Category>
<ns2:CategoryId>800018</ns2:CategoryId>
<ns2:CategoryName>Name3</ns2:CategoryName>
<ns2:Categories/>
</ns2:Category>
<ns2:Category>
<ns2:CategoryId>800028</ns2:CategoryId>
<ns2:CategoryName>Name4</ns2:CategoryName>
<ns2:Categories/>
</ns2:Category>
</ns2:Categories>
</ns2:Category>
<ns2:Category>
<ns2:CategoryId>800009</ns2:CategoryId>
<ns2:CategoryName>Name5</ns2:CategoryName>
<ns2:Categories>
<ns2:Category>
<ns2:CategoryId>800019</ns2:CategoryId>
<ns2:CategoryName>Name6</ns2:CategoryName>
<ns2:Categories>
<ns2:Category>
<ns2:CategoryId>800119</ns2:CategoryId>
<ns2:CategoryName>Name7</ns2:CategoryName>
<ns2:Categories/>
</ns2:Category>
<ns2:Category>
<ns2:CategoryId>800219</ns2:CategoryId>
<ns2:CategoryName>Name111</ns2:CategoryName>
<ns2:Categories/>
</ns2:Category>
</ns2:Categories>
</ns2:Category>
</ns2:Categories>
</ns2:Category>
</ns2:Categories>
</ns2:Category>
How would I find Category object with CategoryId 800119 efficiently? So, Im looking for something like FindCategory(long categoryId) - Prefferably with LINQ to objects. Any other option?
© Stack Overflow or respective owner