Hi guy
In System.Collections.Generic.SortedDictionary one of the constructors takes
an IComparer<Tas its argument.I'd like to sort my dictionary by its key.Im
using
class CComparer : IComparer<person>
{
public int Compare(person p1, person p2)
{
return p1.age.CompareTo(p2.age);
}
}
then
SortedDictionary<person , charlist = new SortedDictionary<person ,
char>(new CComparer());
It works fine but i'd like to use delegates instead. Unfortunately compiler
gives me an error 'cannot convert from 'anonymous method' to
'System.Collections.Generic.IDictionary'' My delegate is mistakenly taken
for IDictionary,which is an argument in another constructor ;/, any ideas?
SortedDictionary<person, charlist = new SortedDictionary<person,
char>(delegate (person p1,person p2)
{ return p1.age.CompareTo(p2.age); });
Best regards!