C# Delegates. Casting not working for some reason -


2 errors appear when try build code. first one: "argument 2 : cannot convert double int." second one: "the best overloaded method calculatepay(double, int, calculate) has invalid arguments. don't understand why casting i've applied in bankholidayshift , normalshift methods isn't working. thanks.

using system; using system.collections.generic; using system.linq; using system.text;  namespace consoleapplication8 {      public delegate int calculate(double val1, int val2);      class paycalculator     {          static double hourlypay = 10;         static int hourspershift = 8;          static int normalshift(double hourlypay, int hourspershift)         {             return (int) hourlypay * hourspershift;         }          static int bankholidayshift(double hourlypay, int hourspershift)         {             return (int)(hourlypay * hourspershift) + 50;         }          public static int calculatepay(double a, int b, calculate calc)         {              int totalpay = calc(a, b);             return totalpay;         }          static void main()         {             calculate calc = new calculate(bankholidayshift);              int totalpay =  calculatepay(hourlypay, hourlypay, calc);             console.writeline("total pay shift : {0}", totalpay);             console.readline();         }       } } 

you have int totalpay = calculatepay(hourlypay, hourlypay, calc);, it's spelling, , should have:

int totalpay =  calculatepay(hourlypay, hourspershift, calc); 

btw, local variables, methods parameters, should camelcased.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -