C# Hello World
"Hello, World !!" program in C# is a great way to start for beginners. Here's a simple example:
using System;
class Program
{
static void Main()
{
Console.WriteLine("Hello, World !!");
}
}
Now, let's break it down:
-
using System;
: This line tells the compiler to include theSystem
namespace, which contains essential classes likeConsole
for input and output operations.
-
class Program
: Defines a class namedProgram
. In C#, the entry point of the program is within a class.
-
static void Main()
: This is the entry point of the program. It's a method namedMain
that serves as the starting point for the program. Thestatic
keyword means that the method belongs to the class itself, not to instances of the class.void
indicates that the method doesn't return any value.
-
Console.WriteLine("Hello, World!");
: This line prints the string "Hello, World!" to the console. TheConsole.WriteLine
method is used to display text, and the semicolon;
indicates the end of the statement.
To run this program, you can use an integrated development environment (IDE) like Visual Studio or a text editor with the .NET SDK installed.
Save the code in a file with a .cs
extension, and then compile and run it using the following commands:
csc YourFileName.cs
YourFileName.exe
Replace YourFileName
with the actual name of your C# file. This will compile and execute your "Hello, World!" program.