コード例 #1
0
        public static void GenericMethods()
        {
            var ng = new NotGeneric();

            int[]    ages  = { 30, 40, 50 };
            string[] names = { "Michael", "Dom", "Stef" };

            ng.Zero <int>(ages);
            ng.Zero <string>(names);

            /*
             *
             * ng.Zero(ages);
             * ng.Zero(names);
             *
             */
            foreach (int age in ages)
            {
                Console.WriteLine(age);
            }

            foreach (string name in names)
            {
                Console.WriteLine(name);
            }
        }
コード例 #2
0
    static void Main()
    {
        NotGeneric iob;

        iob = new NotGeneric(88);

        int v = (int)iob.Getob();

        Console.WriteLine("iob is an instance of NotGeneric.\n" + "Thereor , the value returned by Getob() " +
                          "is object .\n it must be cast to int : " + v + "\n");

        NotGeneric strob = new NotGeneric("Non-Generic class");
        string     str   = (string)strob.Getob();

        Console.WriteLine("iob is an instance of NotGeneric.\n" + "Thereor , the value returned by Getob() " +
                          "is also object .\n it must be cast to string : " + str + "\n");

        iob = strob;
        v   = (int)iob.Getob();
    }