I have an example XML file that looks like this:
<Books>
<Category Genre="Fiction" BookName="book_name" BookPrice="book_price_in_$" />
<Category Genre="Fiction" BookName="book_name" BookPrice="book_price_in_$" />
<Category Genre="NonFiction" BookName="book_name" BookPrice="book_price_in_$" />
<Category Genre="Children" BookName="book_name" BookPrice="book_price_in_$" />
</Books>
I need to collect all the names of books and books and move on to another method. Right now, I get all the book and book names separately in two different ones List<string>using the following command:
List<string>BookNameList = root.Elements("Category").Select(x => (string)x.Attribute("BookName")).ToList();
List<string>BookPriceList = root.Elements("Category").Select(x => (string)x.Attribute("BookPrice")).ToList();
I create a text file and send it back to the calling function (these results must be executed in a text file, the text file has two fields bookname and bookprice).
The following code is used to write to a text file:
for(int i = 0; i < BookNameList.Count; i++)
{
}
- . - . , , foreach (, , ). LINQ ( )? foreach.
# .
,
[Edit]: , , .