Hello World
Hello World is the very first program most people write, a tiny one that just prints a greeting. It is like your first wave hello to the computer, and every C# program has a starting spot called Main.
In this page:
Syntax
using System;
class Program
{
static void Main(string[] args)
{
Console.WriteLine("text");
}
}
Hello World
Every C# program starts execution in a Main method inside a class. Console.WriteLine prints text to standard output followed by a newline. This is the traditional first program used to confirm your setup works.
Note:
The
using System; line imports the namespace that contains Console.Example: Hello World
using System;
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
}
}
Login to try C/C++/Java/PHP code in the editor
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the
view already swaps in the hi_ translation fields (or blanks these
out if untranslated), so this renders correctly for both languages
without a lang_code check here. #}
Common Mistakes
- Forgetting the semicolon at the end of
Console.WriteLine("Hello");, which gives a compile error. - Writing
console.writelinein lowercase, when C# is case-sensitive and the name isConsole.WriteLine. - Running the
.csfile directly instead of building and running the project withdotnet run.
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: