HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to C#VariablesData TypesOperatorsStringsListsConditions (if / else)Loops (for / while)Functions
REFERENCE
📖 Overview
🖥️ Output
📦 Variables & Types
🔢 Numbers & Math
✍️ String
📚 List & Dictionary
🔀 Condition & Loop
🧩 Function
C#›Introduction to C#

Introduction to C#

First steps into Microsoft .NET language C#: using, printing with Console.WriteLine, and comments.

Simple enough for a 5-year-old to understand

Print with Console.WriteLine

With top-level statements in C# 9+, you can write programs without writing a class/Main method. Console.WriteLine prints to the screen and moves to the next line.

Your first program
1
using System;
The namespace required for Console.
ImportThe namespace required for Console.
2
Console.WriteLine("Hello!");
Prints to the screen. A semicolon (;) is mandatory at the end of the line.
Output / InputPrints to the screen. A semicolon (;) is mandatory at the end of the line.
ImportOutput / Input
💡 Hint: Every statement in C# ends with a semicolon (;).

Comment line

Example code
1
using System;
2
// This is a comment — does not run.
Single-line comment with //.
CommentSingle-line comment with //.
3
Console.WriteLine("Code is here");
Only this line runs.
Output / InputOnly this line runs.
CommentOutput / Input

🎯 Exercise & Practice

Test what you've learned — answer, write code, check instantly. (2 left)

1.Which command prints to the screen and moves to the next line in C#?
2.Print exactly Hello World to the screen.

🎯 Expected output: Hello World

Loading editor…

About this topic

C# is a language developed by Microsoft for the .NET platform. It started from a foundation similar to Java, but carved its own path over years: today it allows you to write shorter and more expressive code than Java in many aspects.

C# is a compiled language and is compiled to an intermediate language; the runtime converts this intermediate language into machine code. Since .NET is now open source and cross-platform, C# is not tied only to Windows — the same code runs on Linux and macOS as well.

Top-level statements have arrived in modern C# versions: you no longer have to write a class and a main method for a simple program. While learning, this short form makes things easier, but you will continue to see the classic structure in large projects.

What you will learn

  • C# program structure and namespace logic
  • How to output using Console.WriteLine
  • The necessity of the semicolon
  • What using declarations are used for
  • Top-level statements

When to use?

Console.WriteLine adds a newline, Console.Write does not. WriteLine is the fastest tool when debugging; structured logging is used in real applications because it requires level filtering and writing to files.

C# is case-sensitive and the .NET convention is to capitalize method names. This is the most common typo made by those transitioning from Java.

Common mistakes

Wrong

Console.writeline("Hello");

C# is case-sensitive and .NET method names are written in PascalCase: WriteLine. The compiler gives "error CS0117: 'Console' does not contain a definition for 'writeline'".

Correct

Console.WriteLine("Hello");

Wrong

Console.WriteLine('Hello')

There are two errors: single quotes are for A SINGLE CHARACTER in C#, double quotes are required for text; furthermore, the semicolon at the end of the line is missing. Writing multiple characters inside single quotes gives a "Too many characters in character literal" error.

Correct

Console.WriteLine("Hello");

Wrong

class Program {
    static void main(string[] args) {
        Console.WriteLine("Hello");
    }
}

The entry method name in C# is Main, with a capital M. When written in lowercase, the compiler cannot find the entry point and gives "Program does not contain a static 'Main' method suitable for an entry point".

Correct

class Program {
    static void Main(string[] args) {
        Console.WriteLine("Hello");
    }
}

Frequently asked questions

What is the difference between C# and .NET?

C# is a language, while .NET is the platform that runs it: the runtime, standard library, and tools. F# and Visual Basic also run on the same platform. "Learning C#" practically means learning the .NET library alongside the language.

Does C# only run on Windows?

No, this is outdated information. Since the era starting with .NET Core, C# also runs on Linux and macOS; web servers, containers, and cloud services widely run C# on Linux.

What do using lines do?

They allow you to use types in a namespace without typing their full name. In modern projects, the most frequently used ones are added automatically, so you don't need to write any using statements at all in small programs.

Summary

C# is a compiled language that runs on the .NET platform and is cross-platform. It is case-sensitive, method names are written in PascalCase, and double quotes are used for text.

HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code