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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:44:50+00:00 2026-05-11T21:44:50+00:00

Say I have two lists or arrays of strings. For example: list 1: a,

  • 0

Say I have two lists or arrays of strings. For example:

list 1: “a”, “c”, “b”, “d”, “f”, “e”

list 2: “a”, “d”, “e”, “f”, “h”

List 1 and list 2 are of arbitrary lengths. List 1 may contain elements not in list 2, and visa versa.

I’d like to know when items in list 1 are found in list 2, and more specifically I want to know when an item in list 1 is found in list 2 but is found in a different order than which it is found in list 2, relative to the items in list 2. (Hopefully the example below clarifies this statement).

For example, “a” is found in both lists and is the first item in both lists. So, everything is okay so far. “c” and “b” are found in only the 1st list and so can be ignored. “h” is found in only the 2nd list and can also therefore be ignored.

“d” is found in both the 1st and 2nd list. It is found after “a” (the first item) in the original list. Even though the position within the 1st list is different form the second list, it is is okay because its relative order is the same within the two lists (the second match in common between lists).

In the example above “f” and “e” are in the ‘wrong’ order in list 1, because “e” comes becomes before “f” in the 2nd list. So, I would like to report that “e” and “f” are in the wrong order in the first list. How would I do this?

The solution should be in C#. Thank you!

  • 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-11T21:44:50+00:00Added an answer on May 11, 2026 at 9:44 pm
    
    string[] list1 = {"a", "c", "b", "d", "f", "e"};
    string[] list2 = {"a", "d", "e", "f", "h"};
    int i = 0;
    var list1a = list1.Intersect(list2).Select(l=> new { item = l, order= i++});
    int j = 0;
    var list2a = list2.Intersect(list1).Select(l=> new { item = l, order= j++});
    
    var r = from l1 in list1a join l2 in list2a on l1.order equals l2.order
            where l1.item != l2.item
            select new {result=string.Format("position {1} is item [{0}] on list1  but its [{2}] in list2", l1.item, l1.order, l2.item )};
    
    r.Dump();
    
    

    result

    position 2 is item [f] on list1 but its [e] in list2

    position 3 is item [e] on list1 but its [f] in list2

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

Sidebar

Related Questions

No related questions found

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.