Friday, January 4, 2019

Hello World console App using .Net Core

In the previous post Getting started with .Net Core, we saw on how to setup the environment to create .Net Core applications, once the environment is setup we can go ahead and create .Net Core applications.

In the post we shall create a simple Hello World console application in .Net Core
First create a folder HelloConsole, our sample files will be created inside this folder. Open a command prompt and navigate to this folder. Once in the folder run the following command in the command prompt.

> dotnet new console

This command will create a project file HelloConsole.csproj and a Program.cs file

The project file HelloConsole.csproj contains the metadata about the project, with details like application type, version etc. The following is the content of the simple project file we just created.

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.2</TargetFramework>
  </PropertyGroup>
</Project>

The program file Program.cs, contains the actual logic for the console application. In this sample we will have a console.WriteLine statement printing HelloWorld. The following is the content of our simple console application.

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

Notice that this code is very similar to our traditional .Net Framework, c# console application. It contains a static void main() method which has a console.writeline statement.


Search Flipkart Products:
Flipkart.com

No comments: