C# 使消息框显示变量

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10272740/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 13:07:23  来源:igfitidea点击:

Make a Messagebox display a variable

c#variablesmessagebox

提问by user1350180

I want a MessageBoxto display an intvariable, can anybody help?

我想MessageBox显示一个int变量,有人可以帮忙吗?

回答by jb.

You want to use the MessageBox.Show()method

您想使用MessageBox.Show()方法

int num = 0;
MessageBox.Show(num.ToString());

回答by Frater

jb's answer is correct, if you need some more information MSDN has full documentation at: http://msdn.microsoft.com/en-us/library/aa984357(v=vs.71).aspx

jb 的回答是正确的,如果您需要更多信息 MSDN 有完整的文档:http: //msdn.microsoft.com/en-us/library/aa984357(v=vs.71).aspx

For simple library matters, MSDN nearly always has excellent, easy to understand documentation.

对于简单的库问题,MSDN 几乎总是有优秀的、易于理解的文档。

回答by Liam McInroy

This is really easy. Don't get confused and write int test = 1;, then MessageBox.Show("test:" + 1), because then if test's value changes, that will just print 1instead of test's new value 2.

这真的很容易。不要弄糊涂int test = 1;,然后写,MessageBox.Show("test:" + 1)因为如果test的值改变了,那只会打印1而不是test新的值2

Example:

例子:

int test = 1;
test = test + 1;
MessageBox.Show(test);

回答by Naresh Poonia

It is quite easy to achieve this, see this example:

实现这一点很容易,请参阅此示例:

int a=1;
MessageBox.Show(a+"");

回答by Ashraf Abusada

Use string formatting with the message box:

对消息框使用字符串格式:

int courseId = 0;

DialogResult result = MessageBox.Show(string.Format("Print Course No {0} ?", courseId), "Print Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);