C# by Examples
Simple Code Snippets
Tags
Regex Tester
Privacy
How to use async and await in C#
#async
#fundamentals
When to Use async/await vs Task.Run in C#
#async
#fundamentals
#performance
C# casting and type conversion — explicit cast, as, is, Convert, implicit
#fundamentals
How to check if string is null or empty
#fundamentals
#strings
C# checked and unchecked — integer overflow explained
#fundamentals
#performance
C# collections guide — List, Array, Dictionary, HashSet, Queue, Stack
#collections
#fundamentals
#performance
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
C# Dictionary guide — add, lookup, iterate, and common patterns
#collections
#fundamentals
When to Use Dictionary vs Hashtable in C#
#collections
#fundamentals
C# enum guide — declare, iterate, Flags, and convert to string
#fundamentals
C# events — EventHandler, custom EventArgs, raise and subscribe to events
#fundamentals
#oop
C# Exception Handling — throw, custom exceptions, and exception filters
#fundamentals
#error-handling
When to Use foreach vs for Loop in C#
#fundamentals
#loops
#performance
How to generate random numbers in C#
#fundamentals
#random
C# Generics — generic classes, methods, and constraints explained
#fundamentals
#generics
C# GUID — generate, parse, format, and compare GUIDs
#fundamentals
#strings
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
C# interfaces — define, implement, explicit implementation, and interface vs abstract class
#fundamentals
#oop
How to iterate over a dictionary
#collections
#loops
How to join strings in C#
#fundamentals
#strings
LINQ aggregate methods in C# — Sum, Count, Average, Min, Max, Aggregate
#linq
#collections
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
C# nullable types — int?, Nullable<T>, null handling patterns
#fundamentals
#null-safety
When to use Parse vs TryParse in C#
#fundamentals
#types
Pattern matching in C# — is, switch, property, and list patterns
#fundamentals
#modern-csharp
#patterns
C# properties — get, set, init, auto properties, and computed properties
#fundamentals
#oop
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
C# Regex — pattern matching, groups, replace, and examples
#strings
#regex
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
C# Span<T> and Memory<T> — zero-allocation slicing and high-performance buffers
#performance
#modern-csharp
C# Stack and Queue — push, pop, enqueue, dequeue, and when to use each
#collections
#fundamentals
How to compare strings in C# — ==, Equals, StringComparison, OrdinalIgnoreCase
#strings
#fundamentals
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
How to Write to a Text File in C#
#file-io
#fundamentals