Click here to Skip to main content
16,020,626 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends,
I have one Hotel class that contains many properties. When I retrieve all hotels data from database, I store them in Generic List object.

Now what I want that I have two properties called LowestPrice and HiestPrice. I want to get Minimum(LowestPrice) and Maximum(HiestPrice) from generic list directly.

Something like HotelList.Min();

Right now I have following logic implemented in my project, but I dont want to use foreach loop.

HotelController h1 = null;
                    HotelController h2 = null;
                    foreach (HotelController h in hList)
                    {
                        if (h1 == null && h2 == null)
                        {
                            h1 = h;
                            h2 = h;
                            continue;
                        }
                        if (h.CheapestRate < h1.CheapestRate)
                        {
                            h1 = h;
                        }
                        if (h.CheapestRate > h2.CheapestRate)
                        {
                            h2 = h;
                        }
                    }
                    minPrice = Convert.ToInt32(h1.CheapestRate.ToString());
                    maxPrice = Convert.ToInt32(h2.CheapestRate.ToString());


Thanks and Regard
Imrankhan
Posted

 
Share this answer
 
I add reference for LinqBridge.dll and I am working on framework 2.0 but still I can't able to use Linq method.
I am doing something like this.
double d = hList.Max(l => l.CheapestRate);
but it tells me invalid expression >
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900