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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:27:28+00:00 2026-06-12T01:27:28+00:00

Can someone explain why result1 is false and result2 is true ? code is

  • 0

Can someone explain why result1 is false and result2 is true? code is given below:

namespace TestCsharp
{
    class Program
    {
        static void Main(string[] args)
        {
            Order objOrder = new Order(0.0M);

            bool result1 = objOrder.PriceNullable.Equals(0);//returns false
            bool result2 = objOrder.PriceNullable.Value.Equals(0);// returns true
        }
    }

    public class Order
    {
        public decimal? PriceNullable { get; set; }
        public Order(decimal? priceNullable)
        {
            PriceNullable = priceNullable;

        }
    }
}   
  • 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-06-12T01:27:29+00:00Added an answer on June 12, 2026 at 1:27 am

    Because System.Decimal exposes an overload of Equals that can accept a Decimal value, and your second case is invoking that method (having converted the int parameter to a decimal using an implicit conversion) and returning true.

    Whereas in the first case, the Nullable is trying its best, but can only invoke Object.Equals which will fail when comparing between an int and a decimal. If your first call was:

    bool result1 = objOrder.PriceNullable.Equals(0M);
    

    You’d be comparing two decimals, and it will now return true.


    The Nullable generic Equals method can invoke neither the implicit conversion from int to decimal, nor the overload of equals that accepts a decimal value.

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

Sidebar

Related Questions

Can someone explain why the result of the code below would be class B::1
Can someone explain why in javascript, alert({} == true) shows false if ({}) alert('true')
can someone explain me why I do get different results? bool result = true;
Can someone explain the following two outputs? Code 1: console.log(itemsAry); //loadNextItem(); function loadNextItem(){ var
Can someone help explain the following bit of code. richTextBox1.Font = new Font(richTextBox1.Font.FontFamily, richTextBox1.Font.Size,
Looking at the following code, can someone explain how values are passed around in
Can someone explain how these results are possible (python 2.6): >>> 1<3>2 True >>>
Can someone please explain the steps this program takes and the order in which
Can someone explain me the execution of this program?? I know what extends keyword
Can someone explain this to me? I have two queries below with their results.

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.