Tutorial: ASP.NET Core First Console Application

Alpesh Patel
3 min readApr 1, 2021

Steps 1 ASP.NET Core — Environment Setup

To use ASP.NET Core in your application, the following must be installed in your system:

Step 2 New Project

Once you have installed the Visual Studio 2019, you can start building a new ASP.NET Core Console Application.

  • Open VS2019
  • On the start page, choose Create a new project.
  • On the Create a New Project dialog box, you will see the following different templates for Web projects. Now select the Console App (.NET Core) template with C#:
  • In the Configure your new project dialog, enter HelloWorldConsoleApp in the Project name box and select you location where it will save. Then choose Create.
  • Now, you can see your new project is created and opened.

Step 3 Run Project

  • Let us run this application, you can do that by pressing Ctrl+F5 or Click on Play button on top.

Reference Code:

static void Main(string[] args)

{

Console.WriteLine(“Hello World!”);

}

  • A console window opens with the text “Hello World!” printed on the screen and some Visual Studio debug information.
  • Press any key to close the console window.

Step 4 Enhance the application

Enhance the application to prompt the name which you entered and display it along with the date and time.

  • Console.WriteLine is use for output and Console.ReadLine is use for input. So let’s use both combination and Enhance our app.
  • In Program.cs replace the contents of the Main method, which is the line that calls Console.WriteLine, with the following code:

Reference Code:

static void Main(string[] args)

{

Console.WriteLine(“Hello!”);

Console.WriteLine(“\nWho are you there?”);

Console.WriteLine(“\nwaiting…for your good name.”);

var name = Console.ReadLine();

var date = DateTime.Now;

Console.WriteLine($”\nHello, {name}, on {date:d} at {date:t}!”);

Console.Write(“\nPress any key to exit…”);

Console.ReadKey(true);

}

  • Now, Again Run Application by pressing Ctrl+F5 or Click on Play button on top.
  • Respond to the prompt by entering a name and pressing the Enter key.
  • Press any key to close the console window.

Thank you ….!

--

--

Alpesh Patel

Technology Specialist and Full-Stack Developer. Find me on linkedin for more details https://www.linkedin.com/in/alpesh-patel-8b930952