2이 코드를 빌드하려고하면 오류가 나타납니다. 첫 번째 : "인수 2 : double에서 int로 변환 할 수 없습니다." 두 번째 : "CalculatePay (double, int, Calculate)에서 가장 오버로드 된 메서드에는 잘못된 인수가 있습니다. BankHolidayShift 및 NormalShift 메서드에 적용한 캐스팅이 작동하지 않는 이유를 이해할 수 없습니다. 감사합니다.
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 for this shift is : {0}", TotalPay);
Console.ReadLine();
}
}
}
당신은 int TotalPay = CalculatePay(HourlyPay, HourlyPay, calc);
분명히 철자이고 당신은 있어야합니다 :
int TotalPay = CalculatePay(HourlyPay, HoursPerShift, calc);
BTW, 지역 변수 및 메소드 매개 변수는 CamelCased 여야합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다