C#

C# – HelloWorld App

In this section we are going to see how we can create a HelloWorld App using C# in Visual Studio.

Creating a new console application (Visual Studio)

  1. Open Visual Studio.
  2. In the toolbar, go to File → New Project.
  3. Select the Console Application project type.
Console App
Program.cs file

Click the Run button or press F5 key to execute the project. A Command Prompt window appears that contains the line HelloWorld.

Output

Explanation

  • The first line of the program using System; – the using keyword is used to include the System namespace in the program. A program generally has multiple using statements.
  • The next line has the namespace declaration. A namespace is a collection of classes. The HelloWorldApp namespace contains the class Program.
  • class Program is a class declaration. The class Program contains the data and method definitions that your program uses. Classes generally contain multiple methods. Methods define the behavior of the class. However, the Program class has only one method: Main.
  • static void Main() defines the Main method, which is the entry point for all C# programs. The Main method states what the class does when executed. Only one Main method is allowed per class.
  • System.Console.WriteLine(“HelloWorld”); method prints a given data (in this example, Hello, world!) as an output in the console window.
  • System.Console.ReadKey(), ensures that the program won’t close immediately after displaying the message. It does this by waiting for the user to press a key on the keyboard. Any key press from the user will terminate the program. The program terminates when it has finished the last line of code in the main() method.

Some Features of C#

  • C# is case sensitive.
  • All statements and expression must end with a semicolon (;).
  • The program execution starts at the Main method.
  • Unlike Java, program file name could be different from the class name.

Shaiv Roy

Hy Myself shaiv roy, I am a passionate blogger and love to share ideas among people, I am having good experience with laravel, vue js, react, flutter and doing website and app development work from last 7 years.

Related Articles

Leave a Reply

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

Check Also
Close
Back to top button