static void Main(string[] args) { //***********************Anonymous*************************************** Add1Delegate1 obj1 = delegate(int num1, int num2) { return(num1 + num2); }; Add2Delegate2 obj2 = delegate(int a) { if (a % 2 == 0) { return(true); } else { return(false); } }; Add3Delegate3 obj3 = delegate(string name) { Console.WriteLine(name); }; Add4Delegate4 obj4 = delegate(int a) { Console.WriteLine(a * a); }; Add5Delegate5 obj5 = delegate(string str) { return(str.Equals(str.ToUpper())); }; Add6Delegate6 obj6 = delegate(string str) { if (str.Length == 0) { return(true); } else { return(false); } }; int val = obj1.Invoke(10, 20); Console.WriteLine(val); bool val1 = obj2.Invoke(10); Console.WriteLine(val1); obj3.Invoke("soumya"); obj4.Invoke(2); Console.WriteLine(obj5("swathi")); Console.WriteLine(obj6("usha")); }
static void Main(string[] args) { // ***************************delegates * *********************************** // // //instating the delagate Add1Delegate1 obj1 = new Add1Delegate1(concat); Console.WriteLine(obj1(10, 20)); Add2Delegate2 obj2 = new Add2Delegate2(Iseven); Console.WriteLine(obj2(2)); Add3Delegate3 obj3 = new Add3Delegate3(message); obj3("soumya"); Add4Delegate4 obj4 = new Add4Delegate4(sqaure); obj4(2); Add5Delegate5 obj5 = new Add5Delegate5(Isupper); Console.WriteLine(obj5("swathi")); Add6Delegate6 obj6 = new Add6Delegate6(IsEmpty); Console.WriteLine(obj6("usha")); Console.ReadKey(); }