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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:14:36+00:00 2026-06-11T09:14:36+00:00

Lets say I have the following class public class Test { public int prop1

  • 0

Lets say I have the following class

public class Test
{
    public int prop1 { get;set; }
    public string prop2 { get;set; }
    public Type prop3 { get;set; }
}

If I have two instances of this class, what is a fast approach to comparing the objects but at the same time allowing me to check if a property is something else assuming it did not match the other objects property. Currently I am just doing a ton of if statements but this feels like a bad way of doing things.

An example of the functionality I want; If first instance prop1 did not match prop1 of second instance I can still check if prop1 from first instance is 10 or something.

Yes this example is very crude but the actual code is HUGE so no way I can post it here.

Thanks

EDIT

I Should note, I can’t edit the class Test as I do not own 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-06-11T09:14:37+00:00Added an answer on June 11, 2026 at 9:14 am

    You can build your own Comparer (untested code)

    public class TestComparer : IEqualityComparer<Test>
    {
        public bool Equals( Test x, Test y )
        {
            if( ReferenceEquals( x, y ) )
                return true;
    
            if( ReferenceEquals( x, null ) || ReferenceEquals( y, null ) )
                return false;
    
            return x.prop1 == y.prop1 &&
                   x.prop2 == y.prop2 &&
                   x.prop3 == y.prop3;
        }
    
        public int GetHashCode( Test entry )
        {
            unchecked
            {
                int result = 37;
    
                result *= 397;
                result += entry.prop1.ToString( ).GetHashCode( );
                result *= 397;
                result += entry.prop2.GetHashCode( );
                result *= 397;
                result += entry.prop3.ToString( ).GetHashCode( );
    
                return result;
            }
        }
    }
    

    and then simply call:

    Test a = new Test( );
    Test b = new Test( );
    
    var equal = new TestComparer( ).Equals( a, b );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say i have following class public class abc { int id; string name;
Lets say i have the following scenario: public class A { public String createString(final
Lets say I have the following: public class MyObject { [Bindable] public var foo:int
Lets say I have the following class: public class Provider { ... public sealed
Lets say a have the following Model public class FirstModel { public List<SecondModel> SecondModels
Lets say that I have the following code: public class Shelter<A extends Animal, B
Lets say I have a library, version 1.0.0, with the following contents: public class
Lets say I have the following code: public class Base { // Some stuff
Lets say i have the following set of interfaces.... public interface IStart { void
Let's say I have following POJO's using Hibernate. public class User { private String

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.