static void Main(string[] args) { //Rectange(); program p = new program(); #region MathDelegate //MathDelegate del1 = new MathDelegate(Add); //MathDelegate del2 = new MathDelegate(program.Sub); //MathDelegate del3 = p.Mul; //MathDelegate del4 = new MathDelegate(p.Div); //MathDelegate del5 = del1 + del2 + del3 + del4; //del5.Invoke(20, 5); //Console.WriteLine(); //del5 -= del3; //del5(22, 7); #endregion SampleDelegate sampleDelegate = new SampleDelegate(MethodOne); sampleDelegate += MethodTwo; int ValueReturnedByDelegate = sampleDelegate.Invoke(2); Console.WriteLine($"Returned Value is {ValueReturnedByDelegate}"); Console.ReadKey(); }
private static void Rectange() { program rect = new program(); RectangelDegate rectDelegate = new RectangelDegate(rect.GetArea); rectDelegate += rect.GetPerimeter; rectDelegate(23.45, 67.89); rectDelegate.Invoke(13.45, 76.89); //Removing a method from delegate object rectDelegate -= rect.GetPerimeter; rectDelegate.Invoke(13.45, 76.89); }