-3

It's in the Title, can it be possible to add delay in a Console.WriteLine ?

            //userAge
        Console.WriteLine("For security reason, you need to be 14 years old or higher to use this program, please enter your age");
            int userAge = Convert.ToInt32 ( Console.ReadLine() );
    if (userAge > 14)
        {
            Console.WriteLine("You're " + userAge + " you are old enough to use this program");
        }
    else {
            Console.WriteLine("You're " + userAge + " years old you need to use this program with the help of your parents");
            return;
        }

For context, I want that if userAge < 14, then console write "You're ... years old, you need the help of your parents", but I want to add a duration for the text after it had been written, to be displayed with a certain duration and then the program closed. Does it is possible ?

1 Answers1

1

You can use Thread.Sleep() to delay the program for a specific amount of time.

For example:

Console.WriteLine("This will be closed in 2 seconds");
Thread.Sleep(2000);
Michael
  • 81
  • 2