嗨,我是全新的,所以不要在我的新秀问题上判断,
namespace Oef5_3_ShowIncome
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Button_Click(object sender, EventArgs e)
{
int YearSalary = Convert.ToInt32(YearSalaryTextBox.Text);
int numberOfYears = Convert.ToInt32(numberOfYearsTextBox.Text);
ShowIncome(YearSalary, numberOfYears);
MessageBox.Show("something something ", Convert.ToString(ShowIncome)));
}
private int ShowIncome(int lalala, int dadada)
{
int results = lalala * dadada;
return results;
}
}
}
in ... MessageBox.Show(“something something”Convert.ToString(ShowIncome))); 我收到以下错误:windows.form.messagebox.show(字符串,字符串)的最佳重载方法匹配有一些无效的参数。
答案 0 :(得分:2)
private void Button_Click(object sender, EventArgs e)
{
int YearSalary = Convert.ToInt32(YearSalaryTextBox.Text);
int numberOfYears = Convert.ToInt32(numberOfYearsTextBox.Text);
int showInCome = ShowIncome(YearSalary, numberOfYears);
MessageBox.Show("something something ", showInCome.ToString()));
}
答案 1 :(得分:2)
在此行中,您调用方法而不将结果保存到变量
ShowIncome(YearSalary, numberOfYears);
你想要做的是这个
int result = ShowIncome(YearSalary, numberOfYears);
然后将结果传递给messagebox方法
MessageBox.Show("something something ", result.ToString()));
答案 2 :(得分:1)
int YearSalary = Convert.ToInt32(YearSalaryTextBox.Text);
int numberOfYears = Convert.ToInt32(numberOfYearsTextBox.Text);
ShowIncome(YearSalary, numberOfYears);
MessageBox.Show("something something ", Convert.ToString(ShowIncome(100000, 5).ToString())));
因为您在不传递参数的情况下调用了方法。
答案 3 :(得分:1)
嗯,你把我认为的解析器弄糊涂了,它不知道如何处理Show Income作为一个论点
private void Button_Click(object sender, EventArgs e)
{
int YearSalary = Convert.ToInt32(YearSalaryTextBox.Text);
int numberOfYears = Convert.ToInt32(numberOfYearsTextBox.Text);
int income = ShowIncome(YearSalary, numberOfYears);
MessageBox.Show("something something ", Convert.ToString(income));
}
或
private void Button_Click(object sender, EventArgs e)
{
int YearSalary = Convert.ToInt32(YearSalaryTextBox.Text);
int numberOfYears = Convert.ToInt32(numberOfYearsTextBox.Text);
MessageBox.Show("something something ", Convert.ToString(ShowIncome(YearSalary, numberOfYears)));
}
答案 4 :(得分:0)
因为你没有将任何参数传递给ShowIncome,所以你有效地尝试在方法组上调用Convert.ToString。
答案 5 :(得分:0)
大家好,我非常感谢你们所有的努力,如果我再次遇到同样的错误如何绕过那个错误,例如使用... result.ToString,甚至提供自己的参数as result.tostring(1000,500);
但是,如果我创建一个变量,我已经看到了我的问题的解决方案 int something = ShowIncome(YearSalary,numberOfYears);
MessageBox.Show(“yay random words lalala”+ Convert.ToString(something));
然后它以某种方式工作,我希望我知道为什么