-3

This is filler because for some reason stack overflow does not want my post to be completely code, even though the question makes is all you need and I really don't know what else here so I'll just post the question now.

using System;

public class Program
{
    public static void Main()
    {
        Console.WriteLine("Welcome to this code!");
        Console.WriteLine("do nothing for 5 seconds . . .");
        //I need to delay the following code
        Console.WriteLine("Which game would you like to play?");
    }
}
Vled
  • 1
  • 6
  • 3
    System.Threading.Thread.Sleep(5000) - if I recall correctly. – 500 - Internal Server Error Mar 10 '21 at 11:01
  • That just delays the whole compilation, I need to delay the code. Why in god's name would you delay the compilation? @500-InternalServerError – Vled Mar 10 '21 at 11:04
  • 1
  • `Thread.Sleep` might be the fastest way, and it would be fine for your console. But it would be a bad practise in other platforms. You could also use a timer variable and let it count down in real-time – Steven Mar 10 '21 at 11:06
  • @500-InternalServerError It really does. I put that exact code in (with a semicolon, of course) and it waited for 5 more seconds to compile, and ran ALL of the code at once. – Vled Mar 10 '21 at 11:10
  • 1
    @Vled there is no way whatsoever that correctly using Thread.Sleep() does what you claim it does. there just isn't. did you, by any chance, compile & run in one step, and add the sleep call over your first Console.WriteLine? – Franz Gleichmann Mar 10 '21 at 11:18
  • This is my exact code ```using System; public class Program { public static void Main() { Console.WriteLine("Welcome to this code!"); Console.WriteLine("do nothing for 5 seconds . . ."); System.Threading.Thread.Sleep(5000); Console.WriteLine("Which game would you like to play?"); } }``` Compilation time: 5.127 seconds. and i apparently have no clue how to format code in comments @FranzGleichmann – Vled Mar 10 '21 at 11:25
  • @Vled there is no way to format code in comments. you aren't supposed to put code in comments. also: where are you getting that compile time from? also: works on my machine. – Franz Gleichmann Mar 10 '21 at 11:28
  • It may look like it is the compile tim but it isn't. I assume you click on "Start" and you see the console after 5 seconds. Go to "Build" and build your application and you will see that it doesn't take 5 seconds to compile. – Heslacher Mar 10 '21 at 11:29
  • @Heslacher Im using dotnetfiddle, it shows the compilation time. – Vled Mar 10 '21 at 12:59
  • Just tried with dotnetfiddle, showing Compile: 1.016s and Execute: 5.017s just how it should be – Heslacher Mar 10 '21 at 13:38
  • @Heslacher Yes but I want the first code to run, and then the other code after the delay. Am I missing something? – Vled Mar 10 '21 at 14:36
  • Yes you mixed up the numbers on dotnetfiddle. And just keep in mind, that dotnetfiddle is just a "NET sandbox for developers to quickly try out code and share code snippets". It is just the wrong tool to see the correct results. `Thread.Sleep()` is the correct answer but you just can't see it in dotnetfiddle. – Heslacher Mar 10 '21 at 14:39
  • @Heslacher Alright, thanks. I can't currently download apps, don't ask, so what browser tools would you suggest I use? – Vled Mar 10 '21 at 15:18
  • Sorry, don't know – Heslacher Mar 10 '21 at 15:19

1 Answers1

2

You can use Thread.Sleep(5000);

Ajay
  • 75
  • 5