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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:09:00+00:00 2026-05-18T00:09:00+00:00

I have a property in a composite control that checks to see if the

  • 0

I have a property in a composite control that checks to see if the value has changed prior to actually setting the related private field and doing a few other things.

However, it appears that it is never evaluating the statement.

Here is the code for the property:

public T SearchCriteria
        {
            get
            {
                return mySearchCriteria;
            }
            set
            {
                if (value != mySearchCriteria)
                {
                    mySearchCriteria = value;
                    EnsureChildControls();
                    SearchGridParser parser = SearchGridParserFactory.GetParser(this.Type);
                    parser.SetSearchPanelControls<T>(this.mySearchCriteria, ref mySearchParametersPanel);
                    GridView.PageIndex = 0;
                }
            }
        }

I have stepped through the code, and everytime it gets to “value != mySearchCriteria” it evaluates to false and skips the code inside the if statement. In fact, it does this even when I change it to “value == mySearchCriteria”.. if just completely skips it no matter how it evaluates!

What the hey?

I’ve tried changing the order of the arguments in the check, and also using object.Equals() but none of these changes have made any difference.

I have overridden Equals, !=, == and GetHashCode.

There are other places in the code where it uses the “==” and “!=” for these object types without a problem, so I know that my overriding is working correctly.

Problem is, this never even hits the overriden methods. I put breaks on “==”, “!=”, “Equals” and “GetHashCode” and none of them are being called when the “value != mySearchCriteria” statement is being evaluated.

It’s like it completely skips evaluating it.

  • 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-18T00:09:01+00:00Added an answer on May 18, 2026 at 12:09 am

    Using == between generic types is almost always a bad idea. Operators are overloaded rather than overridden, so even if there is an == operator on your actual types, the compiler won’t know about it. (That means your claim that you’ve “overridden” == and != is already incorrect – you’ve overloaded those operators. You should make sure you understand the difference, as it’s very important.)

    When you write:

    There are other places in the code where it uses the “==” and “!=” for these object types without a problem, so I know that my overriding is working correctly.

    I suspect those areas aren’t in generic code… they’re where the compiler knows what types are being compared, so knows to use your overloads. That’s very different from your generic situation, where the compiler doesn’t know what to use for ==, so falls back to reference identity.

    I assume you have a generic constraint of where T : class or your code wouldn’t compile at all – but it’s still just going to perform a reference comparison, instead of using whatever overload is provided by the actual type of T.

    Use EqualityComparer.Default<T>.Equals(value, mySearchCriteria) to use overridden implementations of Equals including IEquatable<T>.

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

Sidebar

Related Questions

I have a composite control that has a large number of properties that can
I have a table that has a composite key that consists of two int
Alright, this is a little bit complicated. I have a composite control that contains
I have a composite control that contains a ListBox child control. On postback, the
I have a custom composite control that contains a text box, some validators, as
I have a property in my backing bean that returns html code: public String
I have a property an NSArray property called toolbarButtons that in one instance (when
I have a property that RaisePropertyChanged(PropName, oldValue, true, true) when I don't have any
I have a property on my classes for logging service. private ILogger logger =
I have a property within a class, that I need to iterate through all

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.