字符串数组元素反转

运行效果图:

 1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5
6 namespace 翻转数组元素
7 {
8 class Program
9 {
10 static void Main(string[] args)
11 {
12
13 string[] names = { "刘德华", "张学友", "郭富城", "黎明" };
14 for (int i = 0; i < names.Length; i++)
15 {
16 Console.Write("-" + names[i]);
17 }
18 for (int i = 0; i < names.Length / 2; i++)
19 {
20 string temp = names[i];
21 names[i] = names[names.Length - 1 - i];
22 names[names.Length - 1 - i] = temp;
23 }
24 Console.WriteLine();
25 for (int i = 0; i < names.Length; i++)
26 {
27 Console.Write("-" + names[i]);
28 }
29 Console.ReadKey();
30 }
31 }
32 }

 

 

posted on 2011-12-07 00:20  Lightt  阅读(306)  评论(0编辑  收藏  举报