CSharp Examples
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.
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.
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.
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.
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.
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.
HTTP GET JSON with cancellation-based timeout
Performs an HTTP GET, enforces a millisecond timeout, and deserializes the JSON body into the requested type.
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.
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.
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.
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.
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.
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.
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.
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.