I need simple linq Query which will create Dictionary
I have Xml which contains list of customers , who can buy some products
For every customer only one product can be given as free
Below is my sample Xml
I have crated a class that look like
Public Class CustomerFreeItem
{
public string CustomerID
public string FreeproductName
public string ActualPrice
}
<customers>
<customer id="1">
<product name="book" free="false" actualPrice="10"/>
<product name="pen" free="true" actualPrice="10"/>
<product name="scale" free="false" actualPrice="10"/>
</customer>
<customer id="2">
<product name="book" free="true" actualPrice="10"/>
<product name="pen" free="false" actualPrice="10"/>
<product name="scale" free="false" actualPrice="10"/>
</customer>
<customer id="3">
<product name="book" free="false" actualPrice="10"/>
<product name="pen" free="false" actualPrice="10"/>
<product name="scale" free="true" actualPrice="10"/>
</customer>
</customers>
Frome Above Xml i want a Dictionary with customer ID as key and value as FreeProduct (CustomerFreeItem object)
Please suggest
Thanks,
Salmon.
Thus it’s not clear what language you are using (class declaration is invalid both in C# and in VB) here is C# soulution
I used following class declaration:
And I assumed that every customer has exactly one free product.