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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:19:35+00:00 2026-05-20T17:19:35+00:00

I am using C#, I’m fairly new to the language but I have used

  • 0

I am using C#, I’m fairly new to the language but I have used similar languages before so I understand basic syntax.

I have a 2D array of type Object. (X represents what value and Y is what record) It stores two strings in columns 0 and 1 and a MessageBoxIcon in 2 and a MessageBoxButtons in 3.

I would like the ability to swap two records.

I populate a listBox with column 1 every time a change is made to the array. (using a loop) I am happy with this system.
I have placed + and – buttons to the side of the listBox but I cannot figure out how to do the code behind it.

I want it so that when I click the + button it bumps the currently selected record up one record. (I.E. It decreases it’s Y location and increase the Y coordinate of the record above it) It would need to bump all the values associated with that record.

Could someone provide me with a function to do this?

I hope I explained this well enough.

  • 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-20T17:19:35+00:00Added an answer on May 20, 2026 at 5:19 pm

    This will need to be done in the old way for swapping two variable’s values:

    var t = a;
    a = b;
    b = t;
    

    But, with a and b being rows of a 2d array this has to be done one element at a time.

    public void Swap2DRows(Array a, int indexOne, int indexTwo) {
      if (a == null} { throw new ArgumentNullException("a"); }
      if (a.Rank != 2) { throw new InvalidOperationException("..."); }
    
      // Only support zero based:
      if (a.GetLowerBound(0) != 0) { throw new InvalidOperationException("..."); }
      if (a.GetLowerBound(1) != 0) { throw new InvalidOperationException("..."); }
    
      if (indexOne >= a.GetUpperBound(0)) { throw new InvalidOperationException("..."); }
      if (indexTwo >= a.GetUpperBound(0)) { throw new InvalidOperationException("..."); }
    
      for (int i = 0; i <= a.GetUpperBound(1); ++i) {
        var t = a[indexOne, i];
        a[indexOne, i] = a[indexTwo, i];
        a[indexTwo, i] = t;
      }
    }
    

    This could be generalised to handle arbitrary lower bounds.

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

Sidebar

Related Questions

Using RestKit 0.10.1, I have objects served similar to this json format: {objects: [
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
@using(Html.BeginForm(About, User, FormMethod.Post , new { id=aboutme})) { <fieldset> <ul> <li> <label class=block>About me</label>
Using SolrNet for querying & faceting. I have a combination of int, tdate and
using MSQL 2005 I have a continuous set of flow measurements (averaged for each
This could be a duplicate question, but I have no idea what search terms
using this code: Java Server side: ... out = new PrintWriter(this.client.getOutputStream(), true); ... public
Using SSRS 2008 R2 I have a background process that dynamically generates RDL for
Using the new mvc4 now gives us access to use facebook oauth otb. I
Using Java, assuming v1.6. I have a collection where the unique index is a

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.