How to re-arrange my string array position after store the value in the string array?

Posted by Gg under ASP.NET on 9/6/2011 | Points: 10 | Views : 1413 | Status : [Member] | Replies : 2
Hi,

How to re-arrange my string array after store the value in the string array?

for example:
Before arrange:
arr[0]="d"
arr[1]="sa"
arr[2]="c"
arr[3]="bs"

After arrange:
arr[0]="sa"
arr[1]="c"
arr[2]="bs"
arr[3]="d"

Thanks,
gg.




Responses

Posted by: SheoNarayan on: 9/6/2011 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
Create a temporary string variable.

like

string temp = string.Empty;

temp = arr[0];
arr[0] = arr[1];
arr[3] = temp;
temp = arr[1];
arr[1] = arr[2];
....


Hope this will help.

Thanks


Regards,
Sheo Narayan
http://www.dotnetfunda.com

Gg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Niladri.biswas on: 9/7/2011 [Member] Platinum | Points: 25

Up
0
Down
Try this

 string[] arr = new string[] { "d", "sa", "c", "bs" };

arr = arr.ToList().Skip(1).Union(arr).ToArray();


Hope this helps

Best Regards,
Niladri Biswas

Gg, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response