mrName
mrName

Reputation: 117

Overload invalid argument

Hi i'm brand new so don't judge to hard on my rookie question,

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))); i receive the following error: the best overloaded method match for windows.form.messagebox.show(string, string) has some invalid arguments.

Upvotes: 0

Views: 585

Answers (6)

mrName
mrName

Reputation: 117

Hello everyone i thank you all thrully with all my hard, ive learned 2 new ways if i have this same error again how to bypass that error, such as using a ...result.ToString, or even give their own arguments as result.tostring(1000,500);

But i've seen the solution to my problem if i create a variable for example int something = ShowIncome(YearSalary, numberOfYears);

MessageBox.Show("yay random words lalala " + Convert.ToString(something));

then it works somehow, i wish i knew why

Upvotes: 0

Tony Hopkinson
Tony Hopkinson

Reputation: 20320

Hmm, you've confused the parser there I believe, it didn't know waht to do with ShowIncome as an argument

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));
        }

or

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)));
        }

Upvotes: 1

Dharun
Dharun

Reputation: 613

In this line you are calling the method without saving the result to a variable

ShowIncome(YearSalary, numberOfYears);

What you want to do is this

int result = ShowIncome(YearSalary, numberOfYears);

And then pass result to the messagebox method

MessageBox.Show("something something ", result.ToString()));

Upvotes: 2

nolimit
nolimit

Reputation: 824

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())));

because you called the method without passing parameters.

Upvotes: 1

heisenberg
heisenberg

Reputation: 9759

Its because you're not passing any arguments in to ShowIncome, so you're effectively trying to call Convert.ToString on a methodgroup.

Upvotes: 0

Dmytro
Dmytro

Reputation: 17186

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()));
}

Upvotes: 2

Related Questions