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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:28:14+00:00 2026-06-04T20:28:14+00:00

My question is like this one: c# list compare but the only thing to

  • 0

My question is like this one:
c# list compare

but the only thing to note is this:

I’m using .NET Framework 2.0

So how can I compare two lists on C# framework 2 and return a boolean value if the items are different?

instance == anotherone fails
instance.Equals(anotherone) fails.

Edit:

They are both List

Edit 2

I’m trying to compare if the list values are exactly. I can sort them, np for that. The problem is if the count or the values of the items changes. For example:

List1->Item1 = "A"
List1->Item2 = "B"

List2->Item1 = "B"
List2->Item2 = "A"

//must return true


List1->Item1 = "A"
List1->Item2 = "B"

List2->Item1 = "B"
List2->Item2 = "C"

//must return false

List1->Item1 = "A"
List1->Item2 = "B"

List2->Item1 = "B"
List2->Item2 = "A"
List2->Item3 = "A"

//must return false, etc.

Thanks and kind regards.

  • 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-04T20:28:15+00:00Added an answer on June 4, 2026 at 8:28 pm

    For the question that you link to on computing the intersection, you would need to implement your own version of Intersect. This should get you started:

    List<T> Intersect<T>(List<T> first, List<T> second) {
        Dictionary<T, T> potential = new Dictionary<T, T>();
        foreach (var item in first) {
            potential.Add(item, item);
        }
        List<T> intersection = new List<T>();
        foreach (var item in second) {
            if (potential.Remove(item)) {
                intersection.Add(item);
            }
        }
        return intersection;
    }
    

    To handle if they have the same items with the same frequency:

    bool AreSameAsMultiSets(List<T> first, List<T> second) {
        Dictionary<T, int> counts = new Dictionary<T, int>();     
        foreach (var item in first) {
            if (!counts.ContainsKey(item)) {
                counts.Add(item, 0);
            }
            counts[item] = counts[item] + 1;
        }
        foreach (var item in second) {
            if (!counts.ContainsKey(item)) {
                return false;
            }
            counts[item] = counts[item] - 1;
        }
        foreach (var entry in counts) {
            if (entry.Value != 0) {
                return false;
            }
        }
        return true;
    }
    

    You should probably add some error-handling to the above (first is not null, second is not null). Note that you can’t use HashSet<T> since you’re in .NET 2.0.

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

Sidebar

Related Questions

This question looks like this one : Programmatically binding List to ListBox but as
My question is similar to this one , but I would like to replicate
I know there's no one answer to this question, but I'd like to get
Another question like this one was asked, but I don't 'like' the answer (in
this question is like this one , except it's for PHP testing via browser.
My question is not like this one: Browser-independent way to detect when image has
My question like this: I have a JTable, I put a JProgressBar in one
This is like a follow-up question to this one . Basically what I'm doing
This is a similar question to this one . I would like to convert
I feel my question is close to this one, but I want a more

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.