Re: Sorted Dictionary / List woes.

Ryan Heath <[email protected]> Tue, 13 Nov 2007 17:22:17 +0100
Newsgroups gmane.comp.windows.devel.dotnet.winforms
Message-ID <[email protected]>
It depends on how often the sorted list is needed in the program, but
thats something we dont know :)

// Ryan

On Nov 13, 2007 5:04 PM, Nassar, Anthony <[email protected]> wrote:
> Why not encapsulate the Dictionary<long, MessageInfo> in a class that
> implements Idictionary<long, MessageInfo>, and delegate all the calls
> that a dictionary would normally handle to that private instance
> variable? Then add a method like this, to sort the MessageInfo values on
> demand.
>
>        public class Class1 : IDictionary<long, MessageInfo>
>        {
>                public IEnumerable<MessageInfo> GetChronologically()
>                {
>                        List<MessageInfo> sorted = new
> List<MessageInfo>(this.Values);
>                        sorted.Sort(
>                                delegate(MessageInfo left, MessageInfo
> right)
>                                        {
>                                                return
> left._dateTime.CompareTo(right._dateTime);
>                                        });
>                        return sorted;
>                }
>