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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:53:54+00:00 2026-06-04T23:53:54+00:00

I have this arrays: int[] a = {5, 2, 3}; int[] b = {4,

  • 0

I have this arrays:

int[] a = {5, 2, 3}; 
int[] b = {4, 1, 2}; 
string[] c = {"John", "Peter", "Max"};

I need to sort the values ​​of, say, the second array (b[]), but in relation with the other two arrays, so that they get sorted accordingly. For example, 1 will come first as it’s the lowest number, and since 1 in b[] relates to 2 in a[] and "Peter" in c[], then it means that 2 and "peter" will also move to the first sort position too. The same goes for the other two columns; observe:

int[] a = {2, 3, 5}; 
int[] b = {1, 2, 4}; 
string[] c = {"Peter", "Max", "John"};

How would I do this?

  • 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-04T23:53:55+00:00Added an answer on June 4, 2026 at 11:53 pm

    I think I understand what you are saying. You want to sort array a and c based on the values of b.

    You can sort an array by another array using Array.Sort which lets you specify another array for keys for example:

    int[] a = { 5, 2, 3 }; 
    int[] b = { 4, 1, 2 };
    string[] c = { "John", "Peter", "Max" };
    
    Array.Sort(b.ToArray(), c);
    Array.Sort(b.ToArray(), a);
    Array.Sort(b);
    Console.WriteLine(string.Join(", ", a));
    Console.WriteLine(string.Join(", ", b));
    Console.WriteLine(string.Join(", ", c));
    

    This will output your expected values. Note that we use ToArray to create a copy of the arrays when sorting by key, that’s because Array.Sort sorts both they keys and the values, which we don’t want. We don’t sort the Keys (b in this case) till the end.

    That’s how we solve your immediate problem. However, gathered from the comments, you are trying to sort tabular data. When your data has some structure to it, say like this:

    public class Item
    {
        public int A { get; set; }
        public int B { get; set; }
        public string C { get; set; }
    }
    

    It gets a lot easier.

    var items = new[]
    {
        new Item {A = 5, B = 4, C = "John"},
        new Item {A = 2, B = 1, C = "Peter"},
        new Item {A = 3, B = 2, C = "Max"},
    };
    var sortedItems = items.OrderBy(i => i.B).ToArray();
    

    This uses LINQ, which is perfect for what you are trying to do.

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

Sidebar

Related Questions

I have this code to sort a text file using arrays in java, but
I have two arrays that I create like this: public int GameBoard[][] = new
I have this code : #define N 100 //starting size of the array int
How can I join 2 Point3f arrays together? I have tried this but it
i have two arrays like this first array Array ( [0228] => Array (
I have 3 arrays like this: 1st Array ( [0695] => Array ( [loan_number]
I have two arrays the first one has this structure Parameter Keys array array
I have this array of strings private static String[] colorsArray = { #bde876, #ff8581,
I have this generic string to number conversion : enum STRING_BASE : signed int
i have 2 arrays first for Hours and second for minutes, this is my

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.