Beispiel #1
0
        private static void Main(string[] args)
        {
            var names = new IndexNames();

            names[0] = "Apple";
            names[1] = "Banana";
            names[2] = "Cherry";
            names[3] = "Durian";
            for (int i = 0; i < 4; i++)
            {
                Console.WriteLine(names[i]);    //列印資料
            }
            Console.WriteLine(names["Apple"]);  //找到Apple在第0位
            Console.WriteLine(names["Durian"]); //找到Durian在第3位
            Console.WriteLine(names["Kiwi"]);   //找不到Kiwi則回傳-1
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            var name = new IndexNames();

            name[0] = "hello0";
            name[1] = "hello1";
            name[2] = "hello2";
            name[3] = "hello3";
            name[4] = "hello4";
            name[5] = "hello5";
            name[6] = "hello6";
            name[7] = "hello7";
            name[8] = "hello8";
            name[9] = "hello9";
            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine(name[i]);
            }
            Console.WriteLine(name["hello4"]);
            //Console.WriteLine(name[i]);
            //Console.WriteLine(name[i]);

            Console.ReadLine();
        }