-4

我不确定我是否做得对,但是当我在运行时单击CalculateBttn_Click 按钮时,我试图让CalculateGrossPay 方法运行。但是,无论出于何种原因,我都会遇到不断变化的随机语法错误。我不会改变任何东西来实现这一点。我应该制定一个单独的方法来计算总工资。

private void CalculateBttn_Click(object sender, EventArgs e)
{  CalculateGrossPay(decimal hours, decimal rate);

    }




    private decimal CalculateGrossPay(decimal hours, decimal rate)
    {
        decimal result=0.00m;
        decimal standardHours= 0.00m;
        decimal overtimeHours=0.00m;



        if (hours > 40)
        {

            overtimeHours = (hours - 40) * ( (rate) * 1.5m);
            standardHours = 40 * rate;

            DisplayOutPut.Text = name+ NameTextBox.Text + ""; 

            DisplayOutPut.Text = "Gross Pay:" + result;
        }
        else
        {
            standardHours = hours * rate;
            DisplayOutPut.Text = "Hours:" + HoursTextBox.Text;
            DisplayOutPut.Text = "Rate:" + RateTextBox.Text;
        }
        result = standardHours + overtimeHours;
        return result; 

}

4

2 回答 2

4

Methods in C# that specify parameters need to be called with Parameters. CalculateGrossPay defines 2 Parameters the hours and the rate as decimal values.

Therefore you need to call CalculateGrossPay with two decimal values as Parameters (see example).

Please visit the following sites for more information:

Methods MSDN

Variables MSDN


Example:

CalculateGrossPay(10.1,0.4);
于 2013-10-16T12:17:34.173 回答
2

错误在于您调用该方法的方式。您应该调用您的方法,如下所示:

decimal hours = 1;
decimal rate = 5;

CalculateGrossPay(hours, rate);

hours 和 rate 的值可以硬编码,或者您可以从用户界面读取它们。

于 2013-10-16T12:14:14.503 回答