示例#1
0
        public static void Main()
        {
            MyGenericClass <string> strGenericClass1 = new MyGenericClass <string>("Hello World");

            strGenericClass1.genericMethod("Hello World!");

            MyGenericClass <Student> strGenericClass2 = new MyGenericClass <Student>(new Student());

            //following will throw an exception
            //MyGenericClass<int> intGenericClass = new MyGenericClass<int>(10);
        }
示例#2
0
        static void Main(string[] args)
        {
            MyGenericClass <int> intGenericClass = new MyGenericClass <int>(10);

            int val = intGenericClass.genericMethod(200);

            add <int> sum = AddNumber;

            Console.WriteLine(sum(10, 20));

            add <string> conct = Concate;

            Console.WriteLine(conct("Hello", "World!!"));
        }
示例#3
0
文件: Program.cs 项目: lesnerd/test
        static void Main(string[] args)
        {
            var str1 = "David";
            var str2 = "Dav";

            MyGenericClass <string> myGenericClass = new MyGenericClass <string>("David");

            myGenericClass.genericMethod("Lesner");

            Console.WriteLine("Before swapping: str1={0} str2={1}", str1, str2);
            myGenericClass.SwapIfGreater(ref str1, ref str2);
            Console.WriteLine("After swapping: str1={0} str2={1}", str1, str2);

            var dateNow = DateTime.Today.Date.ToString();

            Console.WriteLine("Today date is: {0}", dateNow);
            var myDate = myGenericClass.ConvertStringToDateTime <DateTime>(dateNow);

            Console.ReadKey();
        }