1
Answer

When and when not to use the ToString() method

Matt Higgins

Matt Higgins

12y
1.6k
1
Hi

I've got some code which works surprisingly well.

When I use the MessageBox.Show command, sometimes I can get a away without using the To String() method. Anybody can say why this snippet of code works ok please :-

decimal averageIteration = iterationsTotal / iterations.Length;
int maxIterations = iterations.Max();

MessageBox.Show("The average number of iterations needed to win are " + averageIteration + "\n" +
                                "The High number was " + maxIterations + "\n" +
                                "The Lowest number was " + iterations.Min());

The code above does not have any trouble outputting an int or decimal types. No need to even use the ToString() method.

Thanks to anyone who can help answer this for me

Cheers

Matt

Answers (1)