C# Syntax References

C# syntax quick reference: collections, classes, records, LINQ and async, from Microsoft Learn. Every item below is clearly marked as a shortcut, command, or syntax reference.

Most Useful C# Syntax References

C#Syntax

Print to Console

Code example
Console.WriteLine("Hello");

Writes a line to the console.

Learn More
C#Syntax

Declare Variables

Code example
int n = 0; var name = "Ada";

Declares typed or inferred variables.

Learn More
C#Syntax

String Interpolation

Code example
$"Total: {total:C}"

Inserts values into a string.

Learn More
C#Syntax

If / Else

Code example
if (x > 0) { ... } else { ... }

Runs code depending on a condition.

Learn More
C#Syntax

Foreach Loop

Code example
foreach (var item in items) { ... }

Loops over every item.

Learn More
C#Syntax

Create a List

Code example
var names = new List<string> { "Ada" }; names.Add("Bob");

Creates a resizable list.

Learn More
C#Syntax

Define a Class

Code example
public class Dog { public string Name { get; set; } = ""; }

Defines a class with a property.

Learn More
C#Syntax

For Loop

Code example
for (int i = 0; i < 10; i++) { ... }

Loops a set number of times.

Learn More

More C# Syntax References

Frequently Asked Questions

What does this C# syntax reference cover?

It covers 20 common C# patterns and examples, including Print to Console, Declare Variables, String Interpolation, If / Else, Foreach Loop.

Can I copy the C# examples?

Yes. Each reference page includes a copyable code example.

What affects these C# examples?

Check the linked documentation for language or runtime version requirements. Libraries, file paths, terminal quoting and environment settings can differ across systems; no blanket platform compatibility is implied.