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 4603048
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:05:08+00:00 2026-05-22T00:05:08+00:00

Int32 struct doesn’t define operator overload method for == operator, so why doesn’t the

  • 0

Int32 struct doesn’t define operator overload method for == operator, so why doesn’t the code cause compile time error:

if(1 == null) ... ;
  • 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-22T00:05:08+00:00Added an answer on May 22, 2026 at 12:05 am

    Let’s take a step back here. The question is confusing and the answers so far are not very clear as to what is going on here.

    Shouldn’t if(1 == null) cause an error?

    No. That is legal, though dumb.

    How does the compiler deal with operators like “==”? It does so by applying the overload resolution algorithm.

    The first thing we must determine is whether this is a “user defined” equality operator or a “built in” equality operator. The left side is a built-in type. The right side has no type at all. Neither of those are user-defined types. Therefore no user-defined operator will be considered. Only built-in operators will be considered.

    Once we know that, the question is “which built-in operators will be considered?” The built in operators are described in section 7.10 of the spec. They are equality operators on int, uint, long, ulong, decimal, float, double, any enum type, bool, char, object, string and any delegate type.

    All of the equality operators on value types also have a “lifted” form that takes nullable value types.

    We must now determine which of those operators are applicable. To be applicable, there must be an implicit conversion from both sides to the operator’s type.

    There is no implicit conversion from int to any enum type, bool, string or any delegate type, so those all vanish from consideration.

    (There is not an implicit conversion from int to uint, ulong, etc, but since this is a literal one, there is an implicit conversion from 1 to uint, ulong, etc.)

    There is no implicit conversion from null to any non-nullable value type, so those all disappear too.

    What does that leave? That leaves the operators on object, int?, long?, uint?, ulong?, double?, float?, decimal? and char? the remaining nullable types.

    We must now determine which one of those remaining applicable candidates is the unique “best” operator. An operator is better than another operator if its operand type is more specific. “object” is the least specific type, so it is eliminated. Clearly every nullable int can be converted to nullable long, but not every nullable long can be converted to nullable int, so nullable long is less specific than nullable int. So it is eliminated. We continue to eliminate operators in this manner. (In the case of the unsigned types we apply a special rule that says that if int? and uint? are both options then int? wins.)

    I will spare you the details; ultimately that process leaves nullable int as the unique best operand type.

    Therefore your program is interpreted as if((int?)1 == (int?)null), which clearly is legal, and will always be false.

    Int32 struct doesn’t define operator overload method for == operator

    You are correct. What does that have to do with anything? The compiler is perfectly able to do the analysis without it. I don’t understand the relationship you believe this fact has to your question. The fact is about a method that could be defined on a type, the question is about how overload resolution chooses a lifted built-in operator. Those two things are not related because “int” is not a user-defined type.

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

Sidebar

Related Questions

The code below gives an error: Property 'Int32 Key' is not defined for type
Given a struct like this: public struct SomeStruct { public SomeStruct(String stringProperty, Int32 intProperty)
Given the following classes and controller action method: public School { public Int32 ID
Consider these two structures: struct Task { public Int32 Id; public String Name; public
I have structure declaration in a header globalStruct.h #ifndef _GLOBALSTRUCT_H #define _GLOBALSTRUCT_H typedef struct
Possible Duplicate: Why doesn't the CLR always call value type constructors Found next code
typeof(int).Name Will return System.Int32 does anyone know of a way to return int
In C#, int and Int32 are the same thing, but I've read a number
I have this C-code to do multiplications over GF(8): int32_t GaloisMultiply (int32_t a, int32_t
I am using the following methods: public void M1(Int32 a) { // acquire MyMutex

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.