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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:10:12+00:00 2026-05-18T05:10:12+00:00

We have several classes in place for our CMS and I’m trying to get

  • 0

We have several classes in place for our CMS and I’m trying to get equality to work so I can check to see if a generic List contains an item. We have some layers of inheritance which I’ll show you below. Below that, I’ll show you some sample code that behaves contrary to my expectations. If you see something I’ve done wrong, please let me know. I’ve reduced the examples below just to show you the parts related. My actual classes are much bigger but I think this is everything you need to see.

IBaseTemplate.cs

public interface IBaseTemplate {
  bool Equals(IBaseTemplate other);
  string GUID { get; }
}

BasePage.cs

public class BasePage : System.Web.UI.Page, IBaseTemplate, IEquatable<IBaseTemplate> {

  // code to define properties, including GUID

  // various constructors
  public BasePage(string GUID) { 
    this.GUID = GUID;
  }

  // interface methods
  public bool Equals(IBaseTemplate other) {
    return (this.GUID == other.GUID);
  }

}

LandingPage.cs

public class LandingPage : BasePage {
  // a bunch of extra properties and method specific to LandingPage
  // but NO definition for Equals since that's taken care of in BasePage

  public LandingPage(string GUID) : base(GUID) {}
}

SamplePage.aspx.cs

var p1 = new LandingPage("{3473AEF9-7382-43E2-B783-DB9B88B825C5}");
var p2 = new LandingPage("{3473AEF9-7382-43E2-B783-DB9B88B825C5}");
var p3 = new LandingPage("{3473AEF9-7382-43E2-B783-DB9B88B825C5}");
var p4 = new LandingPage("{3473AEF9-7382-43E2-B783-DB9B88B825C5}");

var coll = new List<LandingPage>();
coll.Add(p1);
coll.Add(p2);
coll.Add(p3);

p1.Equals(p4);     // True, as expected
coll.Contains(p4); // False, but I expect True here!

I expect coll.Contains(p4) to return true because even though p1 through p4 are different instances, the inherited Equals method from BasePage compares their GUID properties as required by IBaseTemplate. Did I miss something here?

I looked at the docs for List(T)’s Contains method and I’m implementing IEquatable<T>.Equals where T is IBaseTemplate.

  • 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-18T05:10:13+00:00Added an answer on May 18, 2026 at 5:10 am

    You need to override Object.Equals(Object) as well – see this link.

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

Sidebar

Related Questions

I have several classes that conceptually belong to one tier. They have no common
i have several classes with members called 'Id'. Originally i wanted to store these
I have several classes, that all derives from SuperClass. When the classes are created,
I have several classes such as Order, Customer, etc. These classes serve for holding
If I have interface IFoo, and have several classes that implement it, what is
This is for a web project so i have several classes that inherit from
I have several service classes that have static methods and offer a service to
I have several serializable classes that were compiled without specifying a serialVersionUID. I now
I've worked out most of the code and have several game classes. The one
I have several obj-c classes, each of which require a number of constants that

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.