C# by Examples

Simple Code Snippets

TagsRegex TesterPrivacy

How to use async and await in C#

#async#fundamentals

When to Use async/await vs Task.Run in C#

#async#fundamentals#performance

How to check if string is null or empty

#fundamentals#strings

When to Use const vs readonly in C#

#fundamentals#types

How to convert int to enum in C#

#fundamentals#enums#types

How to convert string to int in C#

#fundamentals#types

How to format DateTime in C#

#fundamentals#datetime

Delegates, lambdas, Func, and Action in C#

#fundamentals#modern-csharp

When to Use Dictionary vs Hashtable in C#

#collections#fundamentals

C# enum guide — declare, iterate, Flags, and convert to string

#fundamentals

When to Use foreach vs for Loop in C#

#fundamentals#loops#performance

How to generate random numbers in C#

#fundamentals#random

When to Use HashSet vs List in C#

#collections#fundamentals#performance

When to Use IEnumerable vs IQueryable in C#

#linq#collections#fundamentals

When to Use Interface vs Abstract Class in C#

#oop#fundamentals#design-patterns

How to iterate over a dictionary

#collections#loops

How to join strings in C#

#fundamentals#strings

How to find elements in a list with LINQ in C#

#linq#collections

How to use LINQ GroupBy in C#

#linq#collections

How to join collections with LINQ in C#

#linq#collections

How to sort with LINQ OrderBy in C#

#linq#collections

How to use LINQ Select in C# (projection examples)

#linq#collections

How to filter collections with LINQ Where

#linq#collections

How to Check if a List is Empty

#collections#linq#fundamentals

When to use List vs Array in C#

#collections#fundamentals

How to Merge Two Lists

#collections#linq

How to use the null coalescing operator in C#

#fundamentals#operators

How to use nullable reference types in C#

#fundamentals#types

When to use Parse vs TryParse in C#

#fundamentals#types

Pattern matching in C# — is, switch, property, and list patterns

#fundamentals#modern-csharp#patterns

How to Read a Text File

#file-io#fundamentals

C# record types — record vs class, with expressions, and immutability

#fundamentals#modern-csharp

When to Use ref vs out Parameters in C#

#fundamentals#methods

How to remove duplicates from a list

#collections#linq

How to sort a list by property in C#

#collections#linq

How to sort a list in C#

#collections#linq

string.Format in C# — syntax, format specifiers, and examples

#strings#fundamentals

How to use string interpolation in C#

#fundamentals#strings

C# string methods cheat sheet — Contains, Split, Replace, Trim, and more

#strings#fundamentals

What is the difference between String and string in C#

#fundamentals#types

How to use StringBuilder in C#

#fundamentals#strings

When to Use Struct vs. Class

#fundamentals#types#oop

How to use switch expressions in C#

#fundamentals#patterns

Task.WhenAll, Task.WhenAny, and Task.Run in C#

#async#fundamentals#performance

How to use try catch finally in C#

#fundamentals#exceptions

When to Use Tuple vs ValueTuple in C#

#fundamentals#types

When to Use var vs Explicit Types in C#

#fundamentals#best-practices

What is BOM Character in C#

#fundamentals#strings#file-io

© 2026 C# by Examples. All snippets are for educational purposes.

A project for the C# community.