C sharp- using messagebox

Started by
3 comments, last by PsychoPumpkin 16 years, 2 months ago
I am writing a program, and I am trying to put the output in a messagebox. I added the windows.forms to the reference list, and also put in the using sysem.windows.forms. My program uses 3 arrays, and all 3 arrays are displayed in the output. My question is do i need to create an object or something in order for all 3 arrays to be displayed in the messagebox?
Advertisement
Well, what do you know how to do with it so far? What part, exactly, is the problem?
The MessageBox class's members are all static functions. You don't need an instance. Don't think you could even make one:

MessageBox.Show((parameters go here))
I understand that. I'm trying to put this part of the code in a message box.

for (int count = 0; count < thirdArray.Length; count++)
{
double product;

product = firstArray[count] * secondArray[count];

Console.WriteLine("{0}\t {1}\t{2}\n", firstArray[count], secondArray[count], product);
}



I'm not exactly sure which route to take in order to put this in a messagebox.
You'll have to create the string then display it in a messagebox.

Here's a quick and dirty way:

string message = "Results:\n";int product;for (int count = 0; count < firstArray.Length; count++){    product = firstArray[count] * secondArray[count];    message += firstArray[count];    message += "\t";    message += secondArray[count];    message += "\t";    message += product;    message += "\n";}MessageBox.Show(message);


Edit :
A prettier way that follows closer to how you were formatting to the console is:
string message = "Results:\n";int product;for (int count = 0; count < firstArray.Length; count++){    product = firstArray[count] * secondArray[count];    message += String.Format("{0}\t{1}\t{2}\n",        firstArray[count], secondArray[count], product);}MessageBox.Show(message);

This topic is closed to new replies.

Advertisement