private void button2_Click(object sender, EventArgs e)
{
int i = 5;
MessageBox.Show(i);
}
Fails..
private void button2_Click(object sender, EventArgs e)
{
int i = 5;
MessageBox.Show("hoo" + i);
}
Works. Why is that??
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
MessageBox.Show()requires a string as its input parameter.The first sample fails because there is no implicit conversion from integer to string.
The second sample succeeds because
"hoo" + ievaluates to a string. This happens because the C# language defines an addition operator which accepts astringand anobject. Theobjectis converted to astringby callingToString(). This string addition operator is always selected when one of the operands to the addition is astring.