Is Equal by IComparable - CSharp System

CSharp examples for System:IComparable

Description

Is Equal by IComparable

Demo Code


using System.Globalization;
using System.Collections.Generic;
using System.Collections;
using System;/*from   www .  j a v a2s  .co  m*/

public class Main{
        /// <summary>
      /// 
      /// </summary>
      /// <typeparam name="U"></typeparam>
      /// <param name="obj1"></param>
      /// <param name="obj2"></param>
      /// <returns></returns>
      public static bool IsEqual (IComparable obj1, object obj2)
      {
         if (obj1 == null || obj2 == null)
            return false;
         return obj1.CompareTo (obj2) == 0;
      }
        /// <summary>
      /// 
      /// </summary>
      /// <typeparam name="U"></typeparam>
      /// <param name="obj1"></param>
      /// <param name="obj2"></param>
      /// <returns></returns>
      public static bool IsEqual<U> (U obj1, U obj2) where U : IComparable<U>
      {
         if (obj1 == null || obj2 == null)
            return false;
         return obj1.CompareTo (obj2) == 0;
      }
}

Related Tutorials