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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:34:35+00:00 2026-05-12T18:34:35+00:00

I am talking about C# language here. Definition of Object.Equals(Object) method in msdn is:

  • 0

I am talking about C# language here.

Definition of Object.Equals(Object) method in msdn is:

Determines whether the specified
Object is equal to the current Object.

If two objects are equal it returns true, however if they are null it returns false:

x.Equals(a null reference (Nothing in
Visual Basic)) returns false.

Why? Because null is not an object.

A NullReferenceException is thrown if the object paremeter is null.

and also we have this:

x.Equals(y) returns the same value as
y.Equals(x).

No problem at all till here. It is very similar to Java. But C# also provides a System.Nullable struct for non-nullable types. As far as I know, a struct is an object. It inherits Object.Equals method.

If I have a struct like this:

struct Car
    {
        public string Make;
        public string Model;
        public uint Year;

        public Car(string make, string model, uint year)
        {
            Make = make;
            Model = model;
            Year = year;
        }
    }

And create four instances:

Car car1 = new Car("make", "model", 2009);
Car car2 = new Car("make", "model", 2009);
Car car3 = new Car("make", "model", 2008);

car1.Equals(car2); // will return true
car1.Equals(car3); // will return false;

And as far as I know we can’t set a struct to a null value. But System.Nullable is a struct and we can do compile this without any errors:

int? i = null;

(I hope that someone can explain this also. Is it a struct or something else?)

My real question is:

i.Equals(null); // returns true!

(Normally x.Equals(y) = y.Equals(x) Of course null.Equals(i) is not valid here… )

Obviously Object.Equals method is overridden here. Maybe it is documented and this is specified. But is this approach correct/nice ? If so what is the difference between == and Equals method for Nullable values?

  • 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-12T18:34:36+00:00Added an answer on May 12, 2026 at 6:34 pm

    I think your confusion is rooted in the following line

    i? = null;
    

    This does not actually create a null value variable. It’s essentially syntatic sugar for the following

    Nullable<int> i = new Nullable<int>();
    

    The resulting property HasValue on i will have the value false. It is not null but instead a value type with empty values. Or just an empty nullable. IMHO, the best way to think of this is that null is convertible to an empty Nullable<T> for any given T.

    Knowing that it makes the line i.Equals(null) a bit easier to understand. It’s syntatic sugar for the following

    Nullable<int> i = new Nullable<int>();
    i.Equals(null);
    

    The type Nullable<T> only overrides Equals(object). The implementation of this method though considers a null value to be Equal to an empty nullable value. So it’s behaving correctly.

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

Sidebar

Ask A Question

Stats

  • Questions 266k
  • Answers 266k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It doesn't work, because friends has no access to privateFunction… May 13, 2026 at 12:42 pm
  • Editorial Team
    Editorial Team added an answer This sounds like a bug in ASIHTTPRequest I fixed earlier… May 13, 2026 at 12:41 pm
  • Editorial Team
    Editorial Team added an answer If make a generic virtual keyboard and not worry about… May 13, 2026 at 12:41 pm

Related Questions

This is something I've always wondered: Why is PHP slower than Java or C#,
I am currently reading Albahari 's C# 3.0 in a Nutshell and on pg.
Is it possible to do CAD/CAM software without having to use C++? My company
I heard that some languages go from interpreted to compiled by unrolling the interpreter

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.