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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:17:38+00:00 2026-06-16T03:17:38+00:00

How do you search a generic collection to see if an object’s properties are

  • 0

How do you search a generic collection to see if an object’s properties are equal?

List<Customer> = customers = GetCustomers();

Customer c = new Customer() { FirstName = "Sam" };

customers.Contains(c); //doesn't work
  • 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-16T03:17:39+00:00Added an answer on June 16, 2026 at 3:17 am

    You need to define “equality” for the object. You can do this several ways.

    1. Override the Equals method of Customer itself, so that it uses what you think of as equality.
    2. Define a custom comparer, which implements IEqualityComparer that you can pass into contains. Do this if you need to use different definitions of “equality” at different times, or if you don’t have the ability to modify the type.

    Note that any time you override Equals for a type it’s important to also override GetHashCode, and vice versa. It’s important to ensure that any objects that are considered equal by the definition of Equals also have the same hash code. It won’t matter in this particular case, but it will matter when using a hash based data structure.

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

Sidebar

Related Questions

Here is a generic question. I'm not in search of the best answer, I'd
Possible Duplicate: How can I search a generic TList for a record with a
I'm searching through a generic list (or IQueryable) which contains 3 columns. I'm trying
im trying to bind a list-view with a generic list but it seems im
I am new to programing and can not find or know what to search
I'm looking at adding some basic search and filtering functionality in a generic/standardized way
I have a search usercontrol that I'd like to make generic. The control itself
I am new to ASP.NET, I am making a search box in my application.
The C# the generic HashSet<T> search performance should be O(1), and the search performance
I have a line of code like this: List<string>[] apples = new List<string>()[2]; Its

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.