Every C# console program writes output with Console.WriteLine. Modern projects often use top-level statements—no explicit Main method required—while the CLR still finds an entry point behind the scenes.
Minimal program
Console.WriteLine("Hello, World");
Console lives in the System namespace (imported by default in SDK-style projects). WriteLine appends a newline; use Write when you do not want one.
Classic Main form
class Program {
static void Main() {
Console.WriteLine("Hello, World");
}
}
Both styles compile to the same IL. The playground accepts top-level statements for shorter lessons—similar ergonomics to scripting in Python but still compiled.
Important interview questions and answers
- Q: What prints text in C#?
A:Console.WriteLinefor stdout in console apps; web apps use different APIs in the ASP.NET track. - Q: Top-level statements vs Main?
A: Top-level code is lowered to a generatedMainby the compiler—one entry point per project.
Self-check
- Which class provides WriteLine?
- What runtime executes compiled C#?
Tip: Top-level statements compile to a generated Main—use them in the playground; classic static void Main() still works in larger projects.
Interview prep
- What prints text in a console app?
Console.WriteLinewrites to stdout with a trailing newline;Console.Writeomits the newline.- Top-level statements vs Main?
Top-level code is lowered to a compiler-generated
Main—one entry point per project either way.