How do I shift items in an array in C#?

Posted by Andy Evans on Stack Overflow See other posts from Stack Overflow or by Andy Evans
Published on 2010-04-20T00:07:53Z Indexed on 2010/04/20 0:13 UTC
Read the original article Hit count: 289

Filed under:
|
|

Let's say that I have an array of strings like this:

1, 2, 3, 4, 5, 6, 7, 8

and I want to shift the elements of the array such that

  1. The first element always remains fixed
  2. Only the remaining elements get shifted like so ...
  3. The last element in the array becomes the 2nd element and is shifted through the array with each pass.

Pass #1: 1, 2, 3, 4, 5, 6, 7, 8
Pass #2: 1, 8, 2, 3, 4, 5, 6, 7
Pass #3: 1, 7, 8, 2, 3, 4, 5, 6
Pass #4: 1, 6, 7, 8, 2, 3, 4, 5

Any assistance would be greatly appreciated.

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET