System.Array

System.Array是一个抽象基类 其定义的实例数组比直接定义数组可用的方法较多 例如:反序 反转 等

Exp:

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Text;
 4 
 5 namespace ConsoleApplication1
 6 {
 7     class Program
 8     {
 9         [STAThread]
10         static void Main(string[] args)
11         {
12             Array objNames =
13                 Array.CreateInstance(typeof(String), 5);
14             objNames.SetValue("zhang san"0);
15             objNames.SetValue("li si"1);
16             objNames.SetValue("wang wu"2);
17             objNames.SetValue("zhao liu"3);
18             objNames.SetValue("qian qi"4);
19 
20             Console.WriteLine("the vlaue of array:");
21             for (int ctr = 0; ctr < 5; ctr++)
22             {
23                 Console.WriteLine("元素{0}:{1}", ctr + 1, objNames.GetValue(ctr));
24             }
25 
26             Console.WriteLine("arry Numis {0}", objNames.Length.ToString());
27 
28             Console.WriteLine("{0} wei", objNames.Rank.ToString());
29 
30             Array.Reverse(objNames);
31             for (int ctr = 0; ctr < 5; ctr++)
32             {
33                 Console.WriteLine("元素{0}:{1}", ctr + 1, objNames.GetValue(ctr));
34             }
35 
36             
37         }
38     }
39 }

posted @ 2008-10-12 23:00  Edward Xie  阅读(209)  评论(0编辑  收藏  举报