Sign in to follow this  
duHOSSval

C sharp- using messagebox

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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);

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this