8

I want a MessageBox to display an int variable, can anybody help?

Liam McInroy
  • 4,339
  • 5
  • 32
  • 53
user1350180
  • 81
  • 1
  • 1
  • 2

6 Answers6

7

You want to use the MessageBox.Show() method

int num = 0;
MessageBox.Show(num.ToString());
jb.
  • 9,921
  • 12
  • 54
  • 90
3

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);
Ashraf Sada
  • 4,527
  • 2
  • 44
  • 48
1

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

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

Frater
  • 690
  • 3
  • 12
0

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 1 instead of test's new value 2.

Example:

int test = 1;
test = test + 1;
MessageBox.Show(test);
Liam McInroy
  • 4,339
  • 5
  • 32
  • 53
0

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

int a=1;
MessageBox.Show(a+"");
sebix
  • 2,943
  • 2
  • 28
  • 43
0

Here: int test = 0; messagebox.show(Convert.ToString(test));

Helper
  • 1
  • 1
    Welcome to StackOverflow. Whenever you post a code fragment please use the code formatting tools. Also please provide explanation as well not just code. – Peter Csala Jun 09 '21 at 11:30