CSharp Examples

C#Oct 23, 2026

Base64 encode and decode UTF-8 text safely

Encodes UTF-8 text as Base64 and decodes it back, rejecting malformed input with a descriptive FormatException.

textvalidationencodingbase64
000
C#Oct 23, 2026

Render an aligned plain-text table from string rows

Renders string rows as an aligned plain-text table with padded columns, a header separator rule and no external packages.

formattingtableterminalconsole
000
C#Oct 23, 2026

Field-level input validation returning error dictionary

Validates signup fields and returns a field-to-message error dictionary instead of throwing on the first problem it finds.

inputrecordserrorsvalidation
000
C#Oct 23, 2026

Build and parse URL query strings with escaping

Builds URL query strings with percent encoding and parses them back into a dictionary, treating plus signs as encoded spaces.

query-stringurlparsingencoding
000
C#Oct 23, 2026

JSON deserialization with line and byte error info

Deserializes JSON and rewraps parse failures with the line, byte position and label so bad payloads are easy to diagnose.

dotnetserializationerrorsjson
000
C#Oct 23, 2026

Bounded worker pool with Parallel.ForEachAsync

Runs items through a fixed number of parallel workers and returns the success count along with every exception that was thrown.

concurrencyasyncworker-poolparallel
000
C#Oct 23, 2026

HTTP GET JSON with cancellation-based timeout

Performs an HTTP GET, enforces a millisecond timeout, and deserializes the JSON body into the requested type.

asynchttpjsontimeout
000
C#Oct 23, 2026

Read and validate environment variables with defaults

Reads environment variables with typed defaults and throws clear errors when required values are missing or fail validation.

environmentconfigurationdotnetvalidation
000
C#Oct 23, 2026

Bounded LRU cache backed by LinkedList and Dictionary

Bounded LRU cache that evicts the least recently used entry once capacity is reached, with constant-time lookups and updates.

lruperformancecachecollections
000
C#Oct 23, 2026

Token bucket rate limiter using Stopwatch

Burst-tolerant token bucket limiter that refills from a monotonic clock and rejects calls that exceed the configured average rate.

concurrencytimingtoken-bucketrate-limiting
000
C#Oct 23, 2026

Multi-key stable sort with nulls last using LINQ

Stable multi-key sort of records by team, score and name, placing records with a null team at the end of the list.

nullssortingrecordslinq
000
C#Oct 23, 2026

Stream a text file line by line with StreamReader

Streams a text file one line at a time with StreamReader, skipping empty lines and never loading the whole file into memory.

ienumerablelinesfile-iostreamreader
000
C#Oct 23, 2026

Chunk an IEnumerable into fixed-size List batches

Splits any IEnumerable into fixed-size List batches, yielding the final partial batch with whatever items remain.

batchingienumerableyieldcollections
000
C#Oct 23, 2026

Deep clone and recursive merge of JsonObject trees

Deep-copies a JsonNode tree and recursively merges JSON objects, with source values overwriting matching target keys.

mergerecursionjsondeep-clone
000
C#Oct 23, 2026

Async retry helper with capped exponential backoff

Retries an async operation with capped exponential backoff and jitter so transient failures recover without hammering a service.

asyncresiliencebackoffretry
000