static void Main(string[] args) { var calc = new SimpleCalculator(); int result; PerformCalculation calcReference; /*calcReference = calc.Sum; * result = calcReference(10, 15); * Console.WriteLine(result);*/ //DoCalculation(10, 15, calc.Sum); //DoCalculation(10, 15, calc.Multiply); PerformCalculation first = calc.Sum; PerformCalculation second = calc.Multiply; second = (PerformCalculation)Delegate.Combine(first, second); result = second(10, 15); Console.WriteLine(result); result = second.Invoke(20, 20); Console.WriteLine(result); PerformCalculation emptyCalculation = null; //NullReferenceException result = emptyCalculation.Invoke(40, 40); Console.WriteLine(result); }
public static void Main232() { //Instantiating a delegate //Using the new keyword PerformCalculation performCal = new PerformCalculation(Add); //Using delegate inference PerformCalculation performCalculation = Add; SecondDelegate secondDelegate = CountEvenNumbers; //Invoking a delegate //Invoking Asynchronously int[] numArray = { 42, 44, 45, 46, 47, 48, 49, 50 }; secondDelegate.BeginInvoke(numArray, null, null); //Using the () operator performCal(40, 45); //Using the Invoke() method of the delegate class performCalculation.Invoke(40, 45); //End on the asynchronous invocation int sam = secondDelegate.EndInvoke(null); }
public Testing() { CountdownCompleted = null; OurDelegate = Calculate; OurDelegate -= Calculate; OurDelegate += Calculate; OurDelegate += Calculate; OurDelegate += Calculate; OurDelegate += CalculateSum; OurDelegate = null; OurDelegate?.Invoke(4, 8); //CountdownCompleted.Invoke(this, new EventArgs()); // CountdownCompleted = null; }
static void Main(string[] args) { Action <int, int> action = New; Func <int, int, string> func = Populate; Predicate <int> predicate = Compare; //Creates a new PerformCalculation type PerformCalculation performCalculation = new PerformCalculation(Add); PerformCalculation perform = Add; perform += Multiply; //add method to feedback to user //add methods to store data in database, send Mail performCalculation(40, 45); performCalculation.Invoke(40, 45); perform.BeginInvoke(40, 45, null, null); //feedback to the user synchronously // store data in database, send Mail runs asynchronously on another thread int sam = perform.EndInvoke(null); }
public int PerformCalculationMethod(int x, int y) { return((PerformCalculationVar?.Invoke(x, y)).GetValueOrDefault()); }
public void Compute(PerformCalculation obj) { int result = obj.Invoke(10, 20); Console.WriteLine(result); }
public void Hi(PerformCalculation calc) { calc.Invoke(1, 5); }