C\delegate usage demonstration

From , 3 Years ago, written in C#, viewed 207 times.
URL https://pastebin.vip/view/45ececbb
  1. // CalculateTax is a delegate that takes a double and returns a double
  2. public delegate double CalculateTax(double x);
  3. static public double StateTax(double x) {
  4.    return x * 0.05;
  5.    }
  6. static public double FederalTax(double x) {
  7.    if (x > 1000.0)
  8.       return x * 0.02;
  9.    else
  10.    return 0.0;
  11. }
  12.  
  13. static void Main(string[] args) {
  14. CalculateTax stateDelegate = new CalculateTax(StateTax);
  15. CalculateTax federalDelegate = new CalculateTax(FederalTax);
  16. double amountOfPurchase = 12.99;
  17. Console.WriteLine("{0}", stateDelegate(amountOfPurchase));
  18. Console.WriteLine("{0}", federalDelegate(amountOfPurchase));
  19.  
  20. Console.In.ReadLine();
  21. }
  22.  
  23. //csharp/4882

Reply to "C\delegate usage demonstration"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website