c# shift the elements of array by 1 with for loop -
im making game in c# , have scoreboard top 5 players. made work, @ least thought did... script enter value of player's name , score in array, there problem. delete last one, if make best score become #1, old #1 deleted , #2 #2 unless make result place. question how move array 1 place (it depends on player's result) , delete last string of it?
edit: can't use list, because im doing stuff array. this:
string topscores = sbname[i].substring(4); int topscoreint = convert.toint32(topscores);
if need use array instead of list
(which has handy insert
method), work way last value forward, replacing each it's predecessor's value, until 1 want update:
int place = 2; // meaning 3rd place, since arrays zero-based // start @ end of array, , replace each value 1 before (int = array.length - 1; > place; i--) { array[i] = array[i - 1]; } // update current place new score array[place] = score;
Comments
Post a Comment