0

I have knowledge in PHP and I want to learn C # language but I do not even do simple addition.

I want to get the value of a ComboBox, convert this value to int and be able to add another value

Despite the conversion done, I have an error : Can not convert type "int" to "string.

My code :

    private void btnValidate_click(object sender, RoutedEventArgs e)
    {
        int number = Test();
    }

    int Test()
    {
        string day = DayBirth.Text;

        int number;
        bool isNumeric = int.TryParse(day, out number);

        if (isNumeric == false)
        {
            Resultat1.Text = "This is not a number";
        }
        else
        {
            Resultat1.Text = number + 10;
        }

        return number;
    }

Thank you

3 Answers 3

1

The issue is that Resultat1.Text is expecting a string, not an int. You can do

Resultat1.Text = (number+10).ToString();

and it should work.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your help it's ok ;)
1

what you need to do is Converting your number to string after addition

Resultat1.Text = (number + 10).ToString;

Comments

1

Text property accept string value not integer so after addition you have to convert it as string

Resultat1.Text = (number + 10).ToString();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.