Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 239421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:35:02+00:00 2026-05-11T20:35:02+00:00

I was poking around in .NET Reflector, and noticed that for reference types like

  • 0

I was poking around in .NET Reflector, and noticed that for reference types like “String” for example, there is an explicit overload of the “==” operator:

typeof(string).GetMethod("op_Equality", BindingFlags.Static | BindingFlags.Public)

returns: System.Reflection.MethodInfo for the “==” operator.

Due to its implementation, you can’t do things like:

if("hi" == 3)  // compiler error, plus code would throw an exception even if it ran)

However, the same thing works for value types:

if((int)1 == (float)1.0)  // correctly returns true
if((int)1 == (float)1.2)  // correctly returns false

I’m trying to figure out exactly how .NET internally handles the type conversion process, so I was looking for the implementation of op_Equality() in .NET Reflector, but “int” doesn’t have one.

typeof(int).GetMethod("op_Equality", BindingFlags.Static | BindingFlags.Public)

returns null.

So, where is the default implementation for the “==” operator for value types?
I’d like to be able to call it via reflection:

public bool AreEqual(object x, object y)
{
    if(x.GetType().IsValueType && y.GetType().IsValueType)
        return x == y; // Incorrect, this calls the "object" equality override
    else
        ...
}

Edit #1:

I tried this, but it didn’t work:

(int)1 == (float)1;                          // returns true
System.ValueType.Equals( (int)1, (float)1 ); // returns false

Edit #2:

Also tried this, but no love:

object x = (int)1;
object y = (float)1.0;

bool b1 = (x == y);                 // b1 = false
bool b2 = ((ValueType)x).Equals(y); // b2 = false

I beleive this .Equals operator on ValueType does not work due to this type check (ripped from .NET Reflector):

ValueType.Equals(object obj)
{
    ...

    RuntimeType type = (RuntimeType) base.GetType();
    RuntimeType type2 = (RuntimeType) obj.GetType();
    if (type2 != type)
    {
        return false;
    }

    ...
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T20:35:02+00:00Added an answer on May 11, 2026 at 8:35 pm

    the evaluation of (int)1 == (float)1.0 doesn’t rely on any special == operator, just the conversion rules.

    The compiler will turn this into (float)((int)1) == (float)1.0

    Edit:
    The rules are specified on MSDN.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Whilst poking around some code using a .NET Reflector for an app I don't
After spending many hours poking around trying to get an ASP .NET AJAX proxy
http://jsfiddle.net/bSnaG/ In my mind the above example should look like a grey box with
Been poking around google and haven't found any like what I'm after. so what
i've been poking around RIM's PlayBook SDK and noticed they extend Object on a
Ok, as I was poking around with building a custom enumerator, I had noticed
In order to support a legacy application that's in the field, I need my
I am currently experimenting with dynamically loaded areas with ASP.NET MVC 3 RC. I've
I am working on Ajax examples from a book and the example from the
I've got a memory leak in Upstart init process (pid 1), what options I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.