Thursday, November 15, 2012

c# Generic List sorting

Here's a quick code snip of sorting a generic list of object, by a DateTime object property in descending order.

1.  Your class has to inherit IComparable
2.  Implement IComparable's CompareTo method
3. After your generic list of objects is built, then call the lists .Sort method.

In this code I needed the LmrMed's serviceDate sorted in descending order.  The Sort method does not create a new list, it changes the order of the nodes in the current list.

I found this article helpful in learning about c# generic list sorting:  http://www.codedigest.com/Articles/CSHARP/84_Sorting_in_Generic_List.aspx


public class LmrMed IComparable<LmrMed>


    {
        public int recId { getset; }
        public string medText { getset; }
        public DateTime? startDate { getset; }
        public DateTime? endDate { getset; }
        public DateTime serviceDate { getset; }

        public LmrMed(int recId, string medText, DateTime startDate, DateTime endDate, DateTime serviceDate)
        {
            this.recId = recId;
            this.medText = medText;
            this.startDate = startDate;
            this.endDate = endDate;
            this.serviceDate = serviceDate;
        }

        public int CompareTo(LmrMed lm)
        {
            return lm.serviceDate.CompareTo(this.serviceDate);
        }



List<LmrMed> lmrMeds = GetMeds(_mrn);
 
            lmrMeds.Sort();

Friday, November 2, 2012

upgrade

I had been thinking about upgrading the stump jumper. This Halloween my wife asked me if I wanted to go to the bike barn. I said sure!  just to look!   Well I ended up getting a 29er Stump Jumper hard tail.
My wife bought it for me. I am a lucky guy!

I was concerned about going to a 29 from a 26. I thought I would feel top heavy.  At the bike barn Kevin took time to explain to me how that's not true. He said I'ts more stable. And it will ride though more stuff than a 26 can. How he explained things was much more detailed and elegant.  

I tried it out in the parking lot, and I wanted the bike that day.  We went home with our new ride.

I took it out on some local trails, and this ride is awesome! I feel I'm riding faster with ease, and I have more balance. Plus I don't feel like I'm inside a bike anymore, it's quite a natural fit.

Thanks to my wonderful wife for such an awesome gift!  Staying fit by mountain biking pays great dividends to all.