Getting started with .NET Core 2 Console application

Lets get started for making a console application on asp.net Core 2. I feel like you have seen the new feature of asp.net core which are very important to see.

As i told you the prerequisites of .Net Core. Open your visual studio on windows go to new project and select .Net Core in left side of window and select Console App(.Net Core) in middle of the window.

Hello World

Now you can see a window opened like program.cs  the code for Hello World has came it is similar like we do in Asp.net simple console application.

 

 using System;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}

 

Execute this code  you will see a flash on the screen because we have not used code to stop the console application and display the message for this we will use Console.Read().

Console.Write("Press any key to continue...");

Console.ReadKey(true);

Now lets play with the console of .Net Core we will make application to take input as name  and Print My name with Current date & time .


Console.WriteLine("\nWhat is your 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);

Conclusion

Finally, you can see the console application is very simple to learn and understand. Play and Enjoy with the code.

  •  
    33
    Shares
  • 33
  •  
  •  
  •  
  •  
  •  

About the Author

Prashant Goswami

I am the blog writer who will teach how to love programming. My experience in programming is about 6 years. And i am the lover of programming , so i will make you people.

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: