加两个no的代码应该是什么? [英] what should be the code for addition of two nos?
本文介绍了加两个no的代码应该是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须在单击按钮时编写代码,以添加两个数字.
谁能说出下面给出的代码为什么不起作用?
I have to write the code on button click for addition of two nos.
Can anyone tell why the code given below is not working?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace myproject
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int number1;
int number2;
int answer;
number1 = 3;
number2 = 5;
answer = number1 + number2;
//MsgBox(answer);
}
}
推荐答案
该代码似乎还可以.要查看结果,您可以编写:
That code seems quite ok. To see the results you can write:
MessageBox.Show(answer.ToString(); //Shows a message box with the content "8"
如果这不是问题,则应向我们显示错误消息.
If this is not the problem, you should show us the error message.
添加文本框以显示结果..
然后,
Add a textbox to display the result..
then,
TextBox1.Text = answer.Tostring();
这篇关于加两个no的代码应该是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文