尝试从 xaml.cs 调用静态方法



对于我的大学项目,我必须设置一个银行应用程序,作为应用程序的一部分,我们必须根据一个人的收入和年龄确定一个人是否有资格开设银行账户。到目前为止,我已经得到了:

public static bool AllowedStatus(decimal income, int age)
    {
        if ((income > minIncome) && (age > minAge))
        {
            return true;
        }
        else
        {
            return false;
        }
    }

在 xaml.cs 文件中,我得到了:

private void CreateAccountButton_Click(object sender, RoutedEventArgs e)
    {
        if (activeAccount.AllowedStatus() == true)
        {
            //ACCOUNT CREATED MESSAGE
        }
        else
        {
            //ACCOUNT INVALID MESSAGE
        }
    }

但我不断收到消息"方法'AllowedStatus'没有重载需要 0 个参数。

如何让 if 语句在 CreateAccountButton_Click 中检查 AllowedStatus 方法中的布尔值,以便我可以执行语句的其余部分?

谢谢汤姆

如果你想

从你的文本框中传递一个小数,那么你可以使用:

private void CreateAccountButton_Click(object sender, RoutedEventArgs e)
{
    decimal income;
    int age;
    if (decimal.TryParse(yourIncomeTextBox.Text, out income)
        && int.TryParse(yourAgeTextBox.Text, out age)
        && activeAccount.AllowedStatus(income, age))
    {
        //ACCOUNT CREATED MESSAGE
    }
    else
    {
        //ACCOUNT INVALID MESSAGE
    }
}

您已将方法定义为具有两个参数:AllowedStatus(十进制收入,整数年龄)。在CreateAccountButton_Click中调用该方法时,必须提供这两个参数。

private void CreateAccountButton_Click(object sender, RoutedEventArgs e)
    {
        if (activeAccount.AllowedStatus(10000, 20) == true) **<-- You have to provide values here**
        {
            //ACCOUNT CREATED MESSAGE
        }
        else
        {
            //ACCOUNT INVALID MESSAGE
        }
    }

最新更新