vendredi 27 janvier 2017

Boolean Program clarification for beginner

Consider the following program:

using System;

class BooleanType
{
    static void Main()
    {
        bool male = false;

        Random random = new Random();
        male = Convert.ToBoolean(random.Next(0, 2));

        if (male) 
        {
            Console.WriteLine("We will use name John");
        } else 
        {
            Console.WriteLine("We will use name Victoria");
        }
    }
}

Question 1. why is the line bool male = false; initialised to false? this seems irrelevant to me as the program later decides if it will be true or false.

Question 2. Random random = new Random(); Why do you have to initialise this to new Random(), doesn't Random random create the variable random of type random?




Aucun commentaire:

Enregistrer un commentaire