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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:52:14+00:00 2026-06-07T06:52:14+00:00

I have a method that I am currently building to compare two lists of

  • 0

I have a method that I am currently building to compare two lists of objects. The lists themselves contain objects

List<TradeFile> list1
List<TradeFile> list2

When I finish comparing TradeFile object from list1 and TradeFile object from list2, I want to return a collection that contains all of the compared TradeFiles and the matching status. So it would be something like:

TradeFile1, TradeFile2, True
TradeFile1, TradeFile2, False

I will use this collection then for reporting later in my process. Should I look at using something like a dictionary that contains a collection of the tradefile objects?

This may work, but really feels messy:

Dictonary<Dictonary<TradeFile,TradeFile>,bool>

Edit:
This is what it ended up looking like based on some the answer below.

private List CompareTradeFileObject(List list1, List list2)
{
List results = new List();
bool matches = false;

        if (list1.Count == list2.Count)
        {
            list1.Sort((x, y) => x.FormatName.CompareTo(y.FormatName));
            list2.Sort((x, y) => x.FormatName.CompareTo(y.FormatName));

            for (int i = 0; i < list1.Count; i++)
            {
                TradeFileCompare tf = new TradeFileCompare();
                tf.TradeFile1 = list1[i];
                tf.TradeFile2 = list2[i];

                if (list1[i].FileExtension == list2[i].FileExtension && list1[i].FormatName == list2[i].FormatName &&
                    list1[i].GroupName == list2[i].GroupName && list1[i].MasterAccountId == list2[i].MasterAccountId)
                {
                    matches = CompareTradeFileContents(list1[i].FileContents, list2[i].FileContents);
                    tf.IsMatch = matches;

                }
                else
                {
                    tf.IsMatch = matches;
                }

                results.Add(tf);
            }
        }
        else
        {
            matches = false;
        }

        return results;
    }

class TradeFileCompare
{
    public TradeFile TradeFile1 { get; set; }
    public TradeFile TradeFile2 { get; set; }
    public bool IsMatch { get; set; }
}
  • 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-07T06:52:17+00:00Added an answer on June 7, 2026 at 6:52 am
    void Main()
    {
        var list1 = new List<TradeFile>(new [] {
            new TradeFile { Name = "TradeFile1", Data = "a" },
            new TradeFile { Name = "TradeFile2",  Data = "b" },
        });
    
        var list2 = new List<TradeFile>(new [] {
            new TradeFile { Name = "TradeFile4",  Data = "a" },
            new TradeFile { Name = "TradeFile5",  Data = "c" },
        });
    
        var query = from tradeFile1 in list1
                    from tradeFile2 in list2
                    select new TradeFileComparison(tradeFile1, tradeFile2);
    
        foreach (var item in query)
        {
            Console.WriteLine(item.ToString());
        }
    }
    
    class TradeFile
    {
        public string Name { get; set; }
    
        public string Data { get; set; }
    
        public bool Matches(TradeFile otherTradeFile)
        {
            return (this.Data == otherTradeFile.Data);
        }
    }
    
    class TradeFileComparison
    {
        public TradeFileComparison(TradeFile tradeFile1, TradeFile tradeFile2)
        {
            this.TradeFile1 = tradeFile1;
            this.TradeFile2 = tradeFile2;
        }
    
        public TradeFile TradeFile1 { get; set; }
    
        public TradeFile TradeFile2 { get; set; }
    
        bool IsMatch { get { return this.TradeFile1.Matches(TradeFile2); } }
    
        public override string ToString()
        {
            return string.Format("{0}, {1}, {2}", 
                this.TradeFile1.Name, this.TradeFile2.Name, 
                this.IsMatch.ToString());
        }
    }
    

    Output:

    TradeFile1, TradeFile4, True
    TradeFile1, TradeFile5, False
    TradeFile2, TradeFile4, False
    TradeFile2, TradeFile5, False
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

All, I have a method that is currently used to invoke DLLs of return
i currently have a method that checks what is around the centre item in
I have a method in Java that concatenates 2 Strings. It currently works correctly,
Currently I have created a ABCFactory class that has a single method creating ABC
I have an audio player that I'm building using AVPlayer. Currently, I keep the
I have a class that currently has several methods that take integer parameters. These
I have method that returns Drawable , and if its Bitmap object is recycled
I have method that returned NSManagedObject and I don't know what kind of NSManagedObject
I have method that returns module path of given class name def findModulePath(path, className):
I have a method that receives something and it needs to determine the type

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.