C# - 没有必要形式参数的参数?

时间:2018-05-07 22:30:00

标签: c#

我收到的错误如下:没有任何参数符合所需的形式参数' bloodPressureSystolicLevel' ' VitalsForm.SetOverallHypertensionLevel(int,int)'。该错误实际出现在我调用方法的行上,SetOverallHypertensionLevel();

调用方法:

    private void picSubmitVitals_Click(object sender, EventArgs e)
    {

        SetOverallHypertensionLevel();
     }

方法:

    private void SetOverallHypertensionLevel(int bloodPressureSystolicLevel, int bloodPressureDiastolicLevel)
    {
        bloodPressureSystolicLevel = Convert.ToInt32(txtSystolic);
        bloodPressureDiastolicLevel = Convert.ToInt32(txtDiastolic);

        if ((bloodPressureSystolicLevel / 200) > (bloodPressureDiastolicLevel / 133))
        {
            if (bloodPressureSystolicLevel >= 160)
            {
                lblHyperStage2.ForeColor = colorSchemeIssue;
            }
            else if (bloodPressureSystolicLevel >= 140)
            {
                lblHyperStage1.ForeColor = colorSchemeIssue;
            }
            else if (bloodPressureSystolicLevel >= 120)
            {
                lblHyperPre.ForeColor = colorSchemeWarning;
            }
            else
            {
                lblHyperNormal.ForeColor = colorSchemeNormal;
            }
        }
        else
        {
                if (bloodPressureDiastolicLevel >= 100)
                {
                    lblHyperStage2.ForeColor = colorSchemeIssue;
                }
                else if (bloodPressureDiastolicLevel >= 90)
                {
                    lblHyperStage1.ForeColor = colorSchemeIssue;
                }
                else if (bloodPressureSystolicLevel >= 80)
                {
                    lblHyperPre.ForeColor = colorSchemeWarning;
                }
                else
                {
                    lblHyperNormal.ForeColor = colorSchemeNormal;
                }

为什么它不识别参数的使用?任何帮助表示赞赏。

2 个答案:

答案 0 :(得分:2)

private void SetOverallHypertensionLevel(int bloodPressureSystolicLevel, int bloodPressureDiastolicLevel)
{
    bloodPressureSystolicLevel = Convert.ToInt32(txtSystolic);
    bloodPressureDiastolicLevel = Convert.ToInt32(txtDiastolic);

应该转换为:

private void SetOverallHypertensionLevel()
{
    var bloodPressureSystolicLevel = Convert.ToInt32(txtSystolic);
    var bloodPressureDiastolicLevel = Convert.ToInt32(txtDiastolic);

因为看起来你想要变量而不是参数

如果您这样做,SetOverallHypertensionLevel();来电将会有效。

答案 1 :(得分:1)

当你打电话给你的方法时

SetOverallHypertensionLevel();

您需要传入方法签名中定义的参数所需的参数。

SetOverallHypertensionLevel(int bloodPressureSystolicLevel, int bloodPressureDiastolicLevel)

所以正确调用该方法的一个例子是:

SetOverallHypertensionLevel(1,1);

您只需提供方法所需的int值。