c# - Change array according to the sequence -


i have image sliders, , wanted change sequence of image slider. current sequence set database field (fetch set of sequence numbers database , show it).

now, want change sequence number.lets say,
slider sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 & need change 4th position slider 8th position , after slider number sequence 1, 2, 3, 5, 6, 7, 4, 8, 9, 10.

here image make easy understand
click here http://i62.tinypic.com/30dl1qb.png

i have int array current sequence,

int[] currentsequence = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; 

mycode:

int[] currentsequence = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; var currentposition = iproductrepositroy.getsingle(x => x.productname.equals(productname)).productsequence;// 4th position var expectedposition = changesequence;// 8th position  if (currentposition < expectedposition)//right shift --> {     int = 0;     (i = (int)currentposition + 1; < expectedposition; i++)     {         // wanted know how change above array here     } } else//left shift <-- {     int i;     (i = (int)currentposition - 1; > expectedposition; i--)     {      } } 

this might easier in list:

class program {     static void main(string[] args)     {         int currentposition = 3;         int expectedposition = 7;          int adjust = (currentposition < expectedposition) ? 1 : 0;         list<int> list = new list<int> { 1,2,3,4,5,6,7,8,9,10};         var item = list[currentposition];         list.removeat(currentposition);         list.insert(expectedposition - adjust , item); //insert position may 1 less @ moment, use calculated adjustment          foreach (int in list)         {             console.writeline(i.tostring());         }         var discard = console.readkey();     } } 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -