static void Main(string[] args) { First111 <int> f = new First111 <int>(); Console.WriteLine(f.add(1, 2)); First111 <string> f1 = new First111 <string>(); Console.WriteLine(f1.add("veerababu", "rallabandi")); //First111<string> s = new First111<string>(); //s.say("veerababu", "rallabandi"); second123 ss = new second123(); Console.WriteLine(ss.compare <string>("veerababu", "veerababu")); Console.WriteLine(ss.compare <int>(40, 40)); //int a = 12; //a.Equals(12); // First111<int> f = new First111<int>(); // Console.WriteLine(f.Max(10, 20)); //Calling Generic class Third22 <int> t = new Third22 <int>(); t.message = 12; t.say(32); //property t.Value = 34; Console.WriteLine(t.Value); Third22 <string> tt = new Third22 <string>(); tt.message = "veeerababu"; tt.say("rallabandi"); //Generic Method calling tt.show <int>(34); tt.show <string>("Madhu"); //calling property tt.Value = "veerababu-rallabandi"; Console.WriteLine(t.Value); //Generic Delegate Calling Fourth <int> ff = new Fourth <int>(); adddelegate <int> ad = new adddelegate <int>(ff.add); Console.WriteLine(ad(20, 30)); ad += ff.sub; Console.WriteLine(ad.Invoke(23, 17)); }
static void Main(string[] args) { // adddelegate obj = add11; //using func delegate // Func<int, float, double, double> obj = add11; //using lambda expressions //Func<int,float,double,double> obj=(a,b,c) => //{ // return a + b + c; //}; Func <int, float, double, double> obj = (x, y, z) => x + y + z; double res = obj.Invoke(12, 1.2f, 23.2); Console.WriteLine(res); //using action delegate //Action<int, float> obj1 = (x,y)=> //{ // Console.WriteLine(x+y); //}; Action <int, float> obj1 = (x, y) => Console.WriteLine(x + y); obj1(10, 12.0f);//or obj1.invoke(12,12.0f); //using predicate delegate Delegate4 dd = new Delegate4(); // Predicate<string> obj2 = dd.compare; //using lambda expression Predicate <string> obj2 = (s) => { if (s.Length > 5) { return(true); } else { return(false); } }; bool a = obj2.Invoke("veerababu"); Console.WriteLine(a); //using func delegate with return bool type Func <string, string, bool> obj3 = compareto; bool res1 = obj3("veera", "veeru"); Console.WriteLine(res1); //anoynums method in delegate //adddelegate obj4 = new adddelegate( // delegate (int x) // { // return x * x; // } // ); //Console.WriteLine("By using anonyomus method with delegate"+obj4(10)); //using Lambda expressiong above above anonymous method adddelegate obj4 = r => r * r; int result = obj4.Invoke(10); Console.WriteLine(result); }