Moving element in array with C# -


is there way move items inside array? example:

int[] myarray = {1,2,3,4}; 

2nd element becomes last:

int[] myarray = {1,3,4,2}; 

p.s.: no that's not homework. can think of @ least 1 solution requires rather difficult implementation:

  • first save second element int
  • then remove element array
  • then add new element @ end of array

any other (read - easier) way this?

there no easy way using array. you'll have loop through array shifting every element index that's moving, , re-insert element @ end. use list<int> it.

list<int> list = myarray.tolist(); int value = list[1]; list.removeat(1); list.add(value); myarray = list.toarray(); 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -