Check if the object is from the given type. - CSharp System

CSharp examples for System:Type

Description

Check if the object is from the given type.

Demo Code


using System.Globalization;
using System.Collections.Generic;
using System.Collections;
using System;//from   www .j a  v a 2  s  .  c  o  m

public class Main{
        /// <summary>
      /// Check if the object is from the given type.
      /// </summary>
      /// <param name="item"></param>
      /// <param name="type"></param>
      /// <returns></returns>
      public static bool IsDifferentType (object item, Type type)
      {
         if (item == null || type == null)
            return true;
         return item.GetType () == type;
      }
        /// <summary>
      /// Check if the 2 objects are from the same type.
      /// </summary>
      /// <param name="item"></param>
      /// <param name="other"></param>
      /// <returns></returns>
      public static bool IsDifferentType (object item, object other)
      {
         if (item == null || other == null)
            return true;
         return item.GetType () == other.GetType ();
      }
}

Related Tutorials