Hello World in C#
Writing your first program in C# is fairly simple. All you need is an IDE -> Visual Studio. For this blog, i am using visual studio 2019.
Steps to follow :
Open visual studio
Click on “Create a new Project”, and select “Console App (.Net Core)
Click Next. Give a proper project name like “Hello World” and desired directory and solution name and click “Create”.
It will take some time a load the project.
Visual studio by default write a few line to get started.
using System;
namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
- Here line one 1 is used for using Console.WriteLine() function. This function lies in this library.
- Line 3 : denotes the name of namespace
- Line 5 : declaration of a class
- Line 7 : Starting point of an application, void means it wont return anything. Static means it does not require instantiation of this class.
- Arguments are not required here. Application can be invoked with arguments depending on the business logic.
- Line 9 : It is used for writing “Hello World” to console.
- Curly braces { } are used to separate the code logic in blocks.
- Hit F5 or start button on UI to get the output
Here you go! you have your first C# program up and running.
Happy Learning !!!