How to sort generic list C#?

I need to sort a list that has temperatures stored in it.

This defines the list:
private List<PollenCountTemp> _pollenCountTemps = new List<PollenCountTemp>();

And this is the method used to get the temperatures:
public void Fill()
        {
            string getPollenHigh = ""; //pollen high count
            string getPollenLow = ""; // pollen low count
            string Temperature = "";


            //setup variables for gathering information
            //Start gathering info from user

            Console.WriteLine("Enter reported temperatures...");
            Console.WriteLine("\n");
            foreach (WeatherStation station in _weatherStations)
            {
                Console.Write(station.StationName);
                Console.WriteLine("\n");
                Console.Write(station.ContactName);
                Console.WriteLine("\n");
                Console.WriteLine("Enter Temperature:");

                Temperature = Console.ReadLine(); // Get string from user
                if (Temperature != null)
                {
                    if (Temperature.Equals("Stop"))
                    {
                        break;
                    }
                    else
                    {

                        Console.WriteLine("\n");
                        Console.WriteLine("Enter Pollen Count:");
                        Console.WriteLine("\n");
                        Console.WriteLine("Enter Pollen High:");
                        getPollenHigh = Console.ReadLine();
                        if (getPollenHigh.Equals("stop"))
                            break;

                        Console.WriteLine("\n");

                        Console.WriteLine("Enter Pollen Low:");
                        getPollenLow = Console.ReadLine();
                        if (getPollenLow.Equals("stop"))
                            break;

                        // Convert it to a number...
                        station.PollenInfo.Temperature = double.Parse(Temperature);

                        // get Pollen high count
                        station.PollenInfo.HighPollenCount = double.Parse(getPollenHigh);


                        // get Pollen low count
                        station.PollenInfo.LowPollenCount = double.Parse(getPollenLow);

                        Console.WriteLine("\n");
                        Console.WriteLine("==============================================");
                    }
                }
            }



LVL 7
MHenryAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

p_davisCommented:
how do you wnat it sorted?


_pollenCountTemps.Sort(delegate(PollenCountTemp pct1, PollenCountTemp pct)
{
    return pct1.Temperature.CompareTo(pct2.Temperator);

});

will do a simple sort

you can also use linq
0
MHenryAuthor Commented:
I need it sorted high to low. I also need to know how to use console.writeline to print out high and low.
0
p_davisCommented:
List<PollenCountTemp> sortedList = (from p in _pollenCountTemps)
_pollenCountTemps = new List<PollenCountTemp>();
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

p_davisCommented:
List<PollenCountTemp> sortedList = (from p in  _pollenCountTemps
order by p.Temperature desc
select p).ToList();


sorry about the last post -- don't know how that happened.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MHenryAuthor Commented:
That's showing this error at the end of the first line

a query body must end with a select clause or a group clause?
0
p_davisCommented:
desc should be descending and order by shouldn't have a space
0
p_davisCommented:
you should also add System.Linq to your usings.
0
MHenryAuthor Commented:
Looks like it's working. How would I print it out? Like this?

Console.WriteLine(_pollenCountTemps[0];
            Console.WriteLine(_pollenCountTemps[8];

Is there a better way to find the end?

0
p_davisCommented:
then for max you can use

Console.WriteLine(sortedList.Max(x=>x.Temperature).ToString());
Console.WriteLine((sortedList.Min(x=>x.Temperature).ToString());
0
MHenryAuthor Commented:
thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.