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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:06:03+00:00 2026-05-23T16:06:03+00:00

Is there any built-in Ordered Collection which support Move-Up and Move-Down of items ?

  • 0

Is there any built-in Ordered Collection which support Move-Up and Move-Down of items ?

i wanna have Ordered Collection(could be List) where i can be sure that when i insert items it will be

inserted at the end of the Collection, then i want to be able to do something like this

Col.MoveUp(Item1);//Takes Item1 and move its index one step up.
                  //if its index is 3 it will be 2 and item on index 2 will be 3
Col.MoveDown(item2);
  • 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-23T16:06:04+00:00Added an answer on May 23, 2026 at 4:06 pm

    It is very easy to build up your own. Here I made them as extension methods. Another option is to define your own collection, inherit it from List and insert these methods there.

    public static class ListExtensions
    {
        public static void MoveUp<T>(this List<T> list, T item)
        {
            int index = list.IndexOf(item);
    
            if (index == -1)
            {
                // item is not in the list
                throw new ArgumentOutOfRangeException("item");
            }
    
            if (index == 0)
            {
                // item is on top
                return;
            }
    
            list.Swap(index, index - 1);
        }
    
        public static void MoveDown<T>(this List<T> list, T item)
        {
            int index = list.IndexOf(item);
    
            if (index == -1)
            {
                // item is not in the list
                throw new ArgumentOutOfRangeException("item");
            }
    
            if (index == list.Count - 1)
            {
                // item is no bottom
                return;
            }
    
            list.Swap(index, index + 1);
        }
    
        private static void Swap<T>(this List<T> list, int i1, int i2)
        {
            T temp = list[i1];
            list[i1] = list[i2];
            list[i2] = temp;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any built-in PHP function through which I can count the sum of
Is there any built-in functionality for classical set operations on the java.util.Collection class? My
Is there any built-in support for that? And if not, is there any consensus
Is there any built in swap function in C which works without using a
Are there any built in functions for SQL where I can pass in a
Is there any built-in function that can return the length of an object? For
Is there any built-in function that multiplies all elements of a list with another?
Is there any built-in method in Java which allows us to convert comma separated
is there any built in function to Concatenate the whole NSMutableArray NSString items i
Is there any built-in C# support for doing an index sort? More Details: I

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.