Slider

C# program to print 'Hello, World!' to the console.

we will write our first C# program in which we will learn how to print the message "Hello World" on the Console screen. C# Code Implementation to Prin
In this article, we will write our first C# program in which we will learn how to print the message "Hello World" on the Console screen. This is an introduction program we write whenever we start learning any new programming language as a beginner.

Example: 
Output: Hello, World!

Steps to Print a Message on Console in C#.

We need to follow the below steps to print our message to the console screen:

Step 1: Open a C# development environment such as Visual Studio or Visual Studio Code.

Step 2: Create a new C# project or open an existing one.

Step 3: Inside the project, create a new C# source code file with the ".cs" extension.

Step 4: In the source code file, use the Console.WriteLine() statement to print "Hello, World!" to the console.

Step 5: Save the file.

Step 6: Build and run the program to see the output.

C# Code Implementation to Print "Hello World!" on Console.

// C# code to print message on console
using System;

namespace HelloWorldApp
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello, World!");
        }
    }
}
Output:
Hello, World!


Explanation of Working:

1. The using System; directive includes the System namespace, which contains fundamental classes and base types.

2. The namespace HelloWorldApp encapsulates the program's code in a specific namespace.

3. The class Program defines a class called Program, which is the entry point of the application.

4. The static void Main(string[] args) method is the starting point of execution. It's the method that gets executed when the program is run.

5. Console.WriteLine("Hello, World!"); is a statement that prints "Hello, World!" to the console and adds a newline character at the end.

Key Note:
The Console.WriteLine() method is used to display output to the console and automatically moves to the next line after printing the message. (alert-passed)
If you want to print the message without moving to the next line, you can use Console.Write() instead. (alert-passed)
0

No comments

Post a Comment

both, mystorymag

DON'T MISS

Nature, Health, Fitness
© all rights reserved
made with by AlgoLesson
Table of Contents