C# Program to print Hello World
Program
using System;
namespace Application
{
public class HelloWorld
{
public static void Main(String[] args)
{
Console.WriteLine("Hello World!!!");
Console.WriteLine("Welcome to oodlescoop");
}
}
}
This C# program prints "Hello World!!!" and "Welcome to oodlescoop" to the console.
-
using System;- Imports the
Systemnamespace, which provides core functionalities, including console input/output.
- Imports the
-
namespace Application- Defines a namespace called
Applicationto group related classes.
- Defines a namespace called
-
public class HelloWorld- Declares a class named
HelloWorld. In C#, all code must be inside a class.
- Declares a class named
-
public static void Main(String[] args)- The
Mainmethod is the entry point of a C# program. staticmeans it belongs to the class and does not require an instance.voidmeans the method does not return any value.String[] argsallows command-line arguments to be passed.
- The
-
Console.WriteLine("Hello World!!!");- Prints
"Hello World!!!"to the console. Console.WriteLine()is used for output with a newline at the end.
- Prints
-
Console.WriteLine("Welcome to oodlescoop");- Prints
"Welcome to oodlescoop"to the console on a new line.
- Prints
Output
$ mcs HelloWorld.cs
$ mono HelloWorld.exe
Hello World!!!
Welcome to oodlescoop