Example #1
0
        static void Main(string[] args)
        {
            //1.
            //Here <T> type become int which is a value type
            GenericClass1 <int> genInt = new GenericClass1 <int>();
            int intData = genInt.GenericMethod(70);

            genInt.GenericProperty = 483;
            Console.WriteLine("{0} - {1}", intData, genInt.GenericProperty);

            //2.
            //Here <T> type become string. Which is a reference type
            GenericClass2 <string> genStr = new GenericClass2 <string>();
            string strData = genStr.GenericMethod("C#");

            genStr.GenericProperty = "Certification Exam: ";
            Console.WriteLine("{0} {1}", strData, genStr.GenericProperty);

            //3.
            //Here 'T' is Myclass. Which has public default constructor
            GenericClass3 <MyClass> genMC = new GenericClass3 <MyClass>();

            //4.
            GenericClass4 <Person4> genPer = new GenericClass4 <Person4>();
            //Student is also a Person. This is also valid.
            GenericClass4 <Student4> genStd = new GenericClass4 <Student4>();

            //5.
            //Here 'T' is IPerson
            GenericClass5 <IPerson> genIPer = new GenericClass5 <IPerson>();
            //Here 'T' is Person which has implement 'IPerson'
            GenericClass5 <Person5> genPer1 = new GenericClass5 <Person5>();
            //Here 'T' is Student it inherit 'Person' which implement 'IPerson'.
            GenericClass5 <Student5> genStd1 = new GenericClass5 <Student5>();

            //6.
            //Here 'T' and 'U' types are same
            GenericClass6 <Person6, Person6> genPP =
                new GenericClass6 <Person6, Person6>();
            //Here 'T' inherit 'U' type
            GenericClass6 <Student6, Person6> genSP =
                new GenericClass6 <Student6, Person6>();
        }
 public static void CrazyGenericMethod <T, U, V, W, X>(GenericClass3 <GenericClass <T>, GenericClass2 <GenericClass3 <U, V, int>, string>, X> gen)
 {
 }