| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- //
- // System.Collections.Comparer
- //
- // Author:
- // Sergey Chaban ([email protected])
- //
- using System;
- using System.Collections;
- namespace System.Collections {
- [Serializable]
- public sealed class Comparer : IComparer {
- public static readonly Comparer Default;
- // Class constructor
- static Comparer ()
- {
- Default = new Comparer ();
- }
- // Public instance constructor
- private Comparer ()
- {
- }
- // IComparer
- public int Compare (object a, object b)
- {
- if (a == b)
- return 0;
- else if (a == null)
- return -1;
- else if (b == null)
- return 1;
- else if (a is IComparable)
- return (a as IComparable).CompareTo (b);
- else if (b is IComparable)
- return -(b as IComparable).CompareTo (a);
- throw new ArgumentException ("Neither a nor b IComparable");
- }
- }
- }
|