Sunday, 27 December 2020

C# Hello World Application

                                                                                               #10 minutes of reading with hands on

 

In this article I will show you what is console application and basics of console application. Console application is light weight program which operates on command prompt. We as programmer needs to provide proper information/message (console messages) so that end user can read and perform operation from command prompt.

Let’s understand with an example. I’m using Visual Studio 2019 community version and console application project from .NET Core framework. There not much difference in .NET Core framework console application and .NET framework console application.

Open visual Studio and click on highlighted create a new project shown in below screen.


It will open below screen. Now select C# as language, operating system as Windows and application type as Console highlighted below. It shows console application from both framework (Core and normal). In this article I’m creating project from Core framework and click Next button.


Set project name HelloWorldProgram


Console application gets created with default class Program and method (Main) inside it.

 

Run console application by using F5 key or in above screen green triangle highlighted, click on it. If you’re using console application from normal .NET framework and not from Core, you need modify main method little bit to hold console screen. 


 

The program executed and print Hello World on command prompt.


Update Main method to read input from console (your name) and print. Console.WriteLine is used to print message on console and Console.ReadLine is used to read input from console.


Same piece of code without Nextline. If you notice in below screen Line is missing in Console.Write and you need to write your name after message ‘Please Enter your Name’. If you enter program execute without reading name.

 

Console.Write: write message on console

Console.WriteLine: write message on console and perform enter key so next message will be printed on new line.

Console.ReadLine(): Read input from console.

 

 

 

 

 

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home