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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:50:03+00:00 2026-05-12T11:50:03+00:00

This seems like a bug to me… I accept that automatic properties, defined as

  • 0

This seems like a bug to me…

I accept that automatic properties, defined as such:

public decimal? Total { get; set; }

Will be null when they are first accessed. They haven’t been initialized, so of course they are null.

But, even after setting their value through +=, this decimal? still remains null. So after:

Total += 8;

Total is still null. How can this be correct? I understand that it’s doing a (null + 8), but seems strange that it doesn’t pick up that it means it should just be set to 8…

Addendums:

I made the “null + 8” point in my question – but notice that it works with strings. So, it does null + “hello” just fine, and returns “hello”. Therefore, behind the scenes, it is initializing the string to a string object with the value of “hello”. The behavior should be the same for the other types, IMO. It might be because a string can accept a null as a value, but still, a null string is not an initialized object, correct?

Perhaps it’s just because a string isn’t a nullable…

  • 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-12T11:50:03+00:00Added an answer on May 12, 2026 at 11:50 am
    public decimal? Total { get; set; }
    

    Think of null as “unknown value”. If you have an unknown quantity of something and you add 8 more, how many do you have now?

    Answer: unknown.

    Operations on Nullable Variables

    There are cases where operations on unknown values give you knowable results.

    public bool? State { get; set; }
    

    The following statements have knowable solutions even though they contain unknown values:

    State = null;
    nextState = State & false;         // always equals false
    nextState = State & true;          // still unknown (null)
    
    nextState = State | true;          // always true
    nextState = State | false;         // still unknown (null)
    

    See the pattern?

    Of course, if you want Total to be equivalent (equal) to 0 when it is null, you can use the null coalescing operator and write something like this:

    Total = (Total ?? 0) + 8;
    

    That will use the value of Total in your equation unless it is null, in which case it will use the value 0.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Seems like fine design to me. I'm not sure about… May 12, 2026 at 10:05 pm
  • Editorial Team
    Editorial Team added an answer It is certainly possible to paint a bmDIB bitmap with… May 12, 2026 at 10:05 pm
  • Editorial Team
    Editorial Team added an answer Calculate the points of a triangle centered in the plane.… May 12, 2026 at 10:05 pm

Related Questions

This seems like a bug to me... I accept that automatic properties, defined as
I am working on a project in eclipse that when I launch using the
There is a strange bug in ListView/GridView in WPF when the SelectionMode is set
The page having problems is... http://schnell.dreamhosters.com/index.php?page=gallery# I use Firebug to debug my jQuery and
We have a MFC 8 application compiled with /CLR that contains a larger amount

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.