private void answer_Click(object sender, EventArgs e)
{
int textbox1;
int textbox2;
int answer;
textbox1 = int.Parse(textBox1.Text);
textbox2 = int.Parse(textBox2.Text);
if (comboBox1.SelectedText.ToString() == "+")
{
answer = (textbox1 + textbox2);
}
else if (comboBox1.SelectedText.ToString() == "-")
{
answer = (textbox1 - textbox2);
}
else if (comboBox1.SelectedText.ToString() == "*")
{
answer = (textbox1 * textbox2);
}
else if (comboBox1.SelectedText.ToString() == "/")
{
answer = (textbox1/textbox2);
}
// the error is here that says Use of unassigned local variable 'answer'
MessageBox.Show(answer.ToString());
}
- 내가 현재의 클래스에 변수 "답"을 선언 한 같은 오류가 왜 이해가 안를 선택합니다.
- 는 어떻게 예를 들어, 메시지 박스에 계산을 표시 할 수 있습니다 :
사용자 TextBox1에에 입력 (12)과 TextBox2를 2, 그래서 그들은 선택 '-'자신의 작업으로 다음 메시지 박스가 10을 표시한다 . 당신이 그것을 정의 할 때은 수학 연산 (C# 산술 연산)
은 전혀 그렇지 않습니다 0 –
에가 ..... –
당신이 저를 제안하고하는 클래스의 상단에 변수 답을 선언하는 것입니다 대답 = 0? 나는 지금 나에게 추천했다. 그러나 메시지 상자는 계산에 textbox1과 textbox2를 사용하지 않으므로 0 –