i have this xml file: (its a draft and got multiple ones like this)
<?xml version="1.0" encoding="UTF-8" ?> <Car> <Location name = "somewhere"> <Type type="itstype"> <Color>Blue</Blue> <Owner>Bill</Owner> <Price>135</Price> </Type> <Type type="itstype"> <Color>Red</Blue> <Owner>John</Owner> <Price>250</Price> </Type> </Location> </Car> and I want using C# to read through all the xml files(which this I can do) and find the highest price for each car in each xml file and display them on the screen. Some xml files have more than two cars. I tried using this but it only displays the highest price on the last xml file it reads.
public List<Cars> carHighestPrice (string carsname) { var highest = from hv in locations from HV in hv.cars orderby HV.votes where hv.locationName == carsName select HV; return highest.ToList(); } this is the method I am using to display them
public void DisplayHighestPrices() { string str = ""; foreach (var highest in locationList.locations) { str = locationList.carHighestPrice (highest.locationName).Last() + Environment.NewLine; } lbl1.Text = str; } any ideas on how to fix that please?
No comments:
Post a Comment