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

  • SEARCH
  • Home
  • 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 7429147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:55:23+00:00 2026-05-29T08:55:23+00:00

This can be applied to many different languages, but I am specifically working with

  • 0

This can be applied to many different languages, but I am specifically working with C# and INotifyPropertyChanged.

If a property is set, should I re-assign its value even if it did not change?
For example:

public int IntProperty
...
set
{
    var oldValue = _intProperty;
    _intProperty = value;
    if (!Equals(value, oldValue))
    {
        OnPropertyChanged(...);
    }
}

vs.

public int IntProperty
...
set
{
    if (!Equals(value, _intProperty))
    {
        _intProperty = value;
        OnPropertyChanged(...);
    }
}

I just can’t decide. Technically, it shouldn’t make a difference, but there are some odd corner cases (like strange Equals implementations that should never happen) that could change the behavior.

  • 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-29T08:55:24+00:00Added an answer on May 29, 2026 at 8:55 am

    This can be influenced by the type of the property. Some classes have intelligent Equals methods, and some don’t. If you trust yours, it shouldn’t matter, but if the class doesn’t override Equals, or doesn’t do it well, then it changes things. On the whole, I’d say that the underlying value shouldn’t change without the notification being sent, so I’d go with #2.

    To give an example, maybe there’s a simple data holder looking something like this:

    class Data
    {
        public int ID { get; set; }
        public string SomeData { get; set; }
        public string SomeOtherData { get; set; }
        //Assume there are lots of other fields here
        public override bool Equals(object obj)
        {
            Data other = obj as Data;
            if (other != null)
            {
                return ID == other.ID;
            }
            return false;
        }
    }
    

    Now if ID is supposed to be unique (possibly because it maps to a DB ID value) then this isn’t that bad of an idea, but it doesn’t stop people from going around creating objects with the same ID and different data values. If some mean person did that you could end up setting a value to a property such as your in which the new value really is significantly different, but .Equals will say they are the same. Now no matter what happens here you’re somewhat screwed, but which is worse, not setting a value that shouldn’t be different but is (because the set is inside the if) or changing the value and not notifying event subscribers that the event changed? (You also have the third option of setting the event and notifying people even if it changed, possibly indicated that this is the case via the event args.) If an event subscriber is code that persists the change to the database (which is often the case with this type of structure) then you’re changing a value in memory, thinking that it really changed (getting it back out is an exact reference match), but the value still won’t be persisted because the event wasn’t fired.

    Sorry for the wall of text.

    tl;dr version, users of this code can find a way to screw you no matter what you do; eventually you need a minimal amount of trust in them for your code to be effective.

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

Sidebar

Related Questions

I've been working with S#arp Architecture but this can probably be applied to any
I am asking this for Ruby, but I guess this principle can be applied
I don't think this can be done cleanly, but I'll ask anyway. I have
Ok, I know this has been asked many times, but my situation is a
In WPF, where can I put styles that should be applied throughout the application?
This can be in any high-level language that is likely to be available on
This can be a good question for finding bugs. No? Okay for beginners at
Using this: Can I use Facebook's fb:friend-selector in an iframe? I created a multi-friend
I asked this Can I automate creating a .NET web application in IIS? a
I know this can be done and i have seen it done using some

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.