icomparer

Advantages/Disadvantages of different implementations for Comparing Objects using .NET

This questions involves 2 different implementations of essentially the same code. First, using delegate to create a Comparison method that can be used as a parameter when sorting a collection of objects: class Foo { public static Comparison<Foo> BarComparison = delegate(Foo foo1, Foo foo2) { return foo1.Bar.CompareTo(fo...

How to use custom IComparer for SortedDictionary?

I am having difficulties to use my custom IComparer for my SortedDictionary<>. The goal is to put email addresses in a specific format ([email protected]) as the key, and sort by last name. When I do something like this: public class Program { public static void Main(string[] args) { SortedDictionary<string, string> l...

IEqualityComparer for class with many properties

Hi all, which is the best implementation for IEqualityComparer for this class ?? The entity has 7 properties. Thanks in advanced. [Serializable()] public class ServidorSeleccionadoDto { [XmlAttribute()] public int Id { get; set; } [XmlAttribute()] public string Nombre { get; set; } [X...

Pass a lambda expression in place of IComparer or IEqualityComparer or any single-method interface?

I happened to have seen some code where this guy passed a lambda expression to a ArrayList.Sort(IComparer here) or a IEnumerable.SequenceEqual(IEnumerable list, IEqualityComparer here) where an IComparer or an IEqualityComparer was expected. I can't be sure if I saw it though, or I am just dreaming. And I can't seem to find an extension...

IComparable and OrderBy. Trying to sort Poker hands with C#.

Hello All, I am attempting to create a simple program that analyzes the poker hands. Given n hands/players and the community cards (Texas hold 'em) I would like to determine the winner(s). However, my test is failing when I have two exact results - it only returns one winner. i.e The hand result contains J J 9 9 K, for both players, but...

C# IComparer<T> standard usage question

I have a question with whether or not this is a standard for using IComparer in C#. Say I have a situation in which there are three Person objects: P1, P2, and P3. Say I call the Compare method passing in P1 and P2 and the result is 0. This essentially means the two people should be categorized as equal. Now say I call the Compare method...

LINQ orderby vs IComparer

I would like to know what is better to use. IComparer class and Compare method for sort or LINQ orderby on List. Both works fine but which one is better for large lists. ...

How to cast 'object' to Class type on IComparer.Compare method

I'm implementing an int IComparer.Compare(object x, object y); from the IComparer interface. I know the objects are of type Class1, and I know one of its members is class1Instance.myDate, of type DateTime. What I want to do is something along the lines of: DateTime.Compare( (Class1)x.myDate, (Class1)y.myDate); But casting this w...