Click here to Skip to main content
11,927,711 members (49,392 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


1 bookmarked

Is operator working simulation

, 10 Jul 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
A simulation of the IS operator working in C#.

This tip shows the simulation of the IS operator working in C#. It isn't an exact replica but instead if IS operator wasn't supported, how else we could produce it.

bool IsOperatorCheck(object arg1, object arg2)
    bool result;
    if (arg1.GetType().IsValueType && arg2.GetType().IsValueType)
        result = (arg1.GetType() == arg2.GetType());
        result = (arg1.GetType().Equals(arg2.GetType()));
    return result;

My guru Jon Skeet says here[^] when to use == and Equals.

Hence in the above code, I have used == for valuetypes and if either of them isn't a valuetype, I am using Equals.

I have tested with valuetypes as well as custom reference type inputs.

P.S: I hope it helps in some way, and I am open for suggestions/learning. Thanks.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer (Senior) Siemens
India India
A .net developer since 4+ years, wild, curious and adventurous nerd.

Loves Trekking/Hiking, animals and nature.

A FOSS/Linux maniac by default Wink | ;)

An MVP aspirant and loves blogging ->

You may also be interested in...

Comments and Discussions

GeneralYes, For your kind info, this tip isnt any attempt to replac... Pin
zenwalker198518-Jul-11 19:54
memberzenwalker198518-Jul-11 19:54 
GeneralRe: I understand that. However, I still see no point in posting ... Pin
Jakub Januszkiewicz19-Jul-11 10:48
memberJakub Januszkiewicz19-Jul-11 10:48 
GeneralReason for my vote of 1 Your comment about <code>==</code> v... Pin
Jakub Januszkiewicz18-Jul-11 13:00
memberJakub Januszkiewicz18-Jul-11 13:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.151126.1 | Last Updated 10 Jul 2011
Article Copyright 2011 by zenwalker1985
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid