'When running a c# code in vs code, i doesn't open the console

The code is:

Console.WriteLine("Hello, World!");Console.ReadKey();

And it gives me this error:

Cannot read keys when either application does not have a console or when console input has been redirected. Try Console.Read



Solution 1:[1]

When creating a new Project in Visual Studio, make sure to select a Console Application Type as your Project Template.

It is possible to change the Project Type after creating a Project through the Project Properties, but since it looks like you are starting from scratch, you might want to restart with a new project template.

Solution 2:[2]

We can found answer in OmniSharp Visual Code docs: https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window

enter image description here

You can also refer to this page: ReadKey not working in .net core

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 permissionBRICK
Solution 2 Jingmiao Xu-MSFT