The snippet library.
Small, practical examples. Search by task or narrow things down below.
Enumerate Unicode code points
C#: EnumerateRunes combines surrogate pairs into Unicode scalar values.
C#✓ Tested
Escape a URL query value
C#: EscapeDataString percent-encodes one value rather than an entire URL.
C#✓ Tested
Escape text for an HTML context
C#: HtmlEncode converts markup delimiters in plain text before rendering it as HTML content.
C#✓ Tested
Explain a calculation with a comment
C#: Keep the code executable while documenting why a fixed input is used.
C#✓ Tested
Extract a substring with range syntax
C#: C# range ends are exclusive; indices operate on UTF-16 code units.
C#✓ Tested
Extract all integer tokens from text
C#: Enumerate Match objects returned by Regex.Matches with an explicit timeout.
C#✓ Tested
Filter even numbers
Use LINQ Where to keep even C# values.
C#✓ Tested
Find a matching item with a fallback
C#: Use the FirstOrDefault overload with an explicit default value.
C#✓ Tested
Find text ignoring case
Use ordinal case-insensitive comparison for a C# substring search.
C#✓ Tested
Find the length of a calendar month
C#: DaysInMonth applies the Gregorian leap-year rules.
C#✓ Tested
Find values common to two collections
C#: Intersect returns distinct values shared by the inputs.
C#✓ Tested
Find values missing from another collection
C#: Except removes duplicates as it calculates the set difference.
C#✓ Tested