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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:04:28+00:00 2026-05-11T01:04:28+00:00

I have to work on some code that’s using generic lists to store a

  • 0

I have to work on some code that’s using generic lists to store a collection of custom objects.

Then it does something like the following to check if a given object’s in the collection and do something if so:

List<CustomObject> customObjects; //fill up the list List<CustomObject> anotherListofCustomObjects; //fill it up  //...  foreach (CustomObject myCustomObject in customObjects) {    if (anotherListofCustomObjects.Contains(myCustomObject))    {       //do stuff    } } 

Problem is is taking forever to process 7000 objects like that.

This is not my code – I am just trying to come up options to improve it – Looks to me it would be much faster to use a dictionary to get the stuff by key instead of looping through the whole collection like the above.

Suggestions?

  • 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. 2026-05-11T01:04:28+00:00Added an answer on May 11, 2026 at 1:04 am

    Well, you seem to have answered it yourself? If you need fast query against a set of data, then a dictionary may be better than a flat list (for largish data sizes, which yours is).

    You could, for example, use the object as its own key –

    Dictionary<CustomObject,CustomObject> ... 

    Note that the meaning of equality depends on the context. If you are passing in the original reference, then that is fine – ContainsKey would do the job. If you have a different but similar-for-the-purposes-of-equality object to compare to, then you’ll need to implement your own GetHashCode(), Equals(), and ideally IEquatable<CustomObject>. Either in CustomObject itself, or in a custom IEqualityComparer<CustomObject>.

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

Sidebar

Ask A Question

Stats

  • Questions 61k
  • Answers 61k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Turns out the problem is that the operation is marked… May 11, 2026 at 9:45 am
  • added an answer I've never seen such constructions in open source projects. It… May 11, 2026 at 9:45 am
  • added an answer You'll need to setup virtual hosts with Apache, and combine… May 11, 2026 at 9:44 am

Related Questions

I have to work on some code that's using generic lists to store a
I have to work on several VB6 legacy projects and despite some good VB6
I have to present some 'process' or 'flow' of the application at work on
I have to work on an old 1.3 JVM and I'm asked to create
Sometimes I have to work on code that moves the computer clock forward. In
Part of a new product I have been assigned to work on involves server-side
I'm trying to get crawl to work on two separate farms I have but
I've have finally got the datepicker to work on my MVC demo site. One
i have to create an asp.net page dynamically on runtime. It should work like
I have had many requests come in to a project that I work on,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.