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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:02:34+00:00 2026-05-23T11:02:34+00:00

I have some data that I read into a jagged array of strings. An

  • 0

I have some data that I read into a jagged array of strings. An example of such arrays:

string[] row = { "John", "Apple", "Orange", "Banana" };

and I will have an array to hold these rows of strings. A very long one.

What I want to do is find all the rows with the same name (“John“). Then compare these rows to see if they are identical. Print all of them if there are any exceptions, otherwise continue to next name.

So for example if I have 10 rows of “John“s, I want to check whether the attributes on all 10 of them are exactly “Apple“, “Orange” and “Banana“. And I will have thousands of names other than “John” that I want to do the same thing with.

Is there an efficient algorithm to do this? I will be writing it in C#.

  • 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-23T11:02:35+00:00Added an answer on May 23, 2026 at 11:02 am

    Using Linq you could do the following:

    var rows = new string[][]
    {
        new string[] {"John", "Apple", "Orange", "Banana"},
        new string[] {"John", "Apple", "Orange", "Banana"},
        new string[] {"John", "Apple", "Lemon", "Banana"},
        new string[] {"John", "Apple", "Orange", "Grape"},
        new string[] {"Sam", "Apple", "Orange", "Banana"},
        new string[] {"Sam", "Apple", "Orange", "Banana"},
    };
    
    var results = (from f in rows
                  where f.Contains("Sam")
                  select f).Distinct(new ArrayComparer());
    

    However, this does require the creation of a custom comparer class as follows:

    class ArrayComparer : IEqualityComparer<string[]>
    {
        public bool Equals(string[] x, string[] y)
        {
            if (x.Length != y.Length)
                return false;
    
            var left = x.OrderBy(s => s).ToArray();
            var right = y.OrderBy(s => s).ToArray();
    
            for (int index = 0; index < x.Length; index++)
            {
                if (left[index] == right[index])
                {
                    continue;
                }
                else
                {
                    return false;
                }
            }
    
            return true;
        }
    
        public int GetHashCode(string[] obj)
        {
            int hash = 23;
            foreach (var element in obj.OrderBy(s => s))
            {
                hash = hash * 37 + element.GetHashCode();
            }
    
            return hash;
        }
    }
    

    The results of using John would be 3 rows and the results with Sam would be 2 rows. If you want to ignore case you would just have to change OrderBy(s => s) to OrderBy(s => s, StringComparer.OrdinalIgnoreCase)

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

Sidebar

Related Questions

I have some json data [{a:10, b:123,c:4.5},{a:2,b:5,c:33}] and so on that I read into
I have some configuration data in a config file that I read off disk
I have binary data in a file that I can read into a byte
I have data stored in a SQL database that I'm attempting to read into
I have some imported csv data that I have turned into an xts object.
I have some data that I need to associate with specific element such as
I have some data that I want to store somewhere in my Rails app
I have some data that won't printf.... echo works, but not printf There is
I have some data that I would like to visualize. Each byte of the
I have some data that I am displaying in 3 column format, of the

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.