none
Random Numbers RRS feed

  • Question

  • I'm learning how to use random numbers with arrays. However, I was wondering of what the 0 and 3 meant whenever I searched how to use a certain type of random class. The code is the following:

    for (int x = 0; x < 20; x++)
                {
                    Console.Write("{0,3}    ", rnd.Next(1, 500));
                    Console.WriteLine();
                }

    Any help is appreciated!

    Monday, December 17, 2018 1:46 AM

Answers

  • This is formatting string syntax that can be roughly translated to "output the first parameter of the function (i.e.: rnd.Next(1, 500) ) with left padding of space to make it 3 characters in length".

    The effect would be similar to right aligned output of 3 characters column width.


    • Edited by cheong00Editor Monday, December 17, 2018 2:05 AM
    • Marked as answer by SamiNeptune Monday, December 17, 2018 2:07 AM
    Monday, December 17, 2018 2:04 AM
    Answerer