int[] intNumbers = {1,2,3,6,5,4,5,3,3,4,2,1,7,888,66,643};//要反转的数组
// intNumbers.Reverse(); //反转
Array.Reverse(intNumbers); //
string a="987654321@-_-@"; //要反转的字符串
char[] ab = a.ToArray(); //必须要转换成集合的形式
Array.Reverse(ab); //对集合进行反转
Response.Write(new string(ab)+"<br/>");
foreach (var item in intNumbers)
{
Response.Write(item.ToString() +" --- ");
}
Response.Write("反转成功");
结果:@-_-@123456789
643 --- 66 --- 888 --- 7 --- 1 --- 2 --- 4 --- 3 --- 3 --- 5 --- 4 --- 5 --- 6 --- 3 --- 2 --- 1 --- 反转成功
字符串反转必须转换成集合才能反转,
如果是集合就可以直接反转
|