Example #1
0
        static void Main(string[] args)
        {
            // 声明一个整型数组
            MyGenericArray <int> intArray = new MyGenericArray <int>(5);

            // 设置值
            for (int c = 0; c < 5; c++)
            {
                intArray.setItem(c, c * 5);
            }
            // 获取值
            for (int c = 0; c < 5; c++)
            {
                Console.Write(intArray.getItem(c) + " ");
            }
            Console.WriteLine();
            // 声明一个字符数组
            MyGenericArray <char> charArray = new MyGenericArray <char>(5);

            // 设置值
            for (int c = 0; c < 5; c++)
            {
                charArray.setItem(c, (char)(c + 97));//char97,98,99,100,101 abcde
            }
            // 获取值
            for (int c = 0; c < 5; c++)
            {
                Console.Write(charArray.getItem(c) + " ");
            }
            Console.WriteLine();
            Console.ReadKey();
        }
Example #2
0
        static void Main(string[] args)
        {
            //declaring an int array
            MyGenericArray <int> intArray = new MyGenericArray <int>(5);

            //setting values
            for (int c = 0; c < 5; c++)
            {
                intArray.setItem(c, c * 5);
            }
            //retrieving the values
            for (int c = 0; c < 5; c++)
            {
                Console.Write(intArray.getItem(c) + " ");
            }
            Console.WriteLine();
            //declaring a character array
            MyGenericArray <char> charArray = new MyGenericArray <char>(5);

            //setting values
            for (int c = 0; c < 5; c++)
            {
                charArray.setItem(c, (char)(c + 97));
            }
            //retrieving the values
            for (int c = 0; c < 5; c++)
            {
                Console.Write(charArray.getItem(c) + " ");
            }
            Console.WriteLine();
            Console.ReadKey();
        }
Example #3
0
        static void Main(string[] args)
        {
            MyGenericArray <int> intArray = new MyGenericArray <int>(5);


            for (int c = 0; c < 5; c++)
            {
                intArray.setItem(c, c * 5);
            }


            for (int c = 0; c < 5; c++)
            {
                Console.Write(intArray.getItem(c) + " ");
            }

            Console.WriteLine();


            MyGenericArray <char> charArray = new MyGenericArray <char>(5);


            for (int c = 0; c < 5; c++)
            {
                charArray.setItem(c, (char)(c + 97));
            }


            for (int c = 0; c < 5; c++)
            {
                Console.Write(charArray.getItem(c) + " ");
            }
            Console.WriteLine();

            Console.ReadKey();
        }