有时候需要使用一个数据字典的表来罗列大批的数据,这时使用List是比较好的方法。
- class Program
- {
- public static Liststring> STAR_LIST = new Liststring>() { "Kobe","James","Wade","Durant"};
- static void Main(string[] args)
- {
- int index1 = STAR_LIST.IndexOf("Kobe");
- int index2 = STAR_LIST.IndexOf("James");
- int index3 = STAR_LIST.IndexOf("Wade");
- Console.WriteLine("{0},{1},{2}", index1, index2, index3);
- Console.ReadLine();
- }
- }
上面的球星表清晰的列出了有那些球星。在实际开发过程中,这个表被用于的机率很高。main()中的使用是就是典型的应用之一,用来取得相应的索引。