Here is the First Program in C# Language,
Codes – First Program of C#
using System; namespace HelloWorld { class Program { static void Main(string[] args) { Console.WriteLine("Hello, World!"); } } }
Explanation – Line By Line
using System;
- The Line includes the system namespace, which is a collection of classes, such as “console” that provide commonly used functionalities. It allow the program to use methods from the system library without needing to fully qualify them.
namespace HelloWorld
- A namespace is a container for classes and other types. It helps organize code and prevents name conflicts. Here, “HelloWorld” is the name of the namespace.
class Program
- Classes are the building blocks of C# programs. A class defines a type, including its data and behavior. Program is the name of this class.
static void Main(string[] args)
- This line defines the
Main
method, which is the entry point of a C# application. static
: The method belongs to the class itself rather than an instance of the class.void
: The method does not return a value.Main
: The name of the method. It is case-sensitive and must be capitalized.string[] args
: An array of strings representing command-line arguments passed to the application.
{
- This opening brace marks the beginning of the Main method’s body.
Console.WriteLine("Hello, World!");
- This line outputs the text “Hello, World!” to the console.
Console
: A class in the System namespace that provides methods for interacting with the console.WriteLine
: A method of the Console class that writes a line of text to the console."Hello, World!"
: A string literal that represents the text to be printed.