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); }
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!!")); }
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(); }