The snippet library.
Small, practical examples. Search by task or narrow things down below.
Add a dictionary entry only if absent
C#: TryAdd reports a duplicate key without replacing its existing value.
C#✓ Tested
Add calendar days
Use DateOnly for a date without a time zone in C#.
C#✓ Tested
Append a line
Append UTF-8 text without replacing existing C# file contents.
C#✓ Tested
Await an asynchronous method result
C#: Use Task<T> for an async operation with a typed result.
C#✓ Tested
Await multiple tasks while preserving result order
C#: Task.WhenAll returns results in the same order as the supplied tasks.
C#✓ Tested
Build text incrementally with StringBuilder
C#: Append fragments instead of repeatedly concatenating intermediate strings in a loop.
C#✓ Tested
Calculate a product with Aggregate
C#: Supply a seed to define the result for an empty sequence.
C#✓ Tested
Calculate a simple total
C#: Multiply a unit price by a quantity, then add a delivery fee.
C#✓ Tested
Calculate an integer beyond the 64-bit range
C#: Use BigInteger for arbitrary-precision integer arithmetic.
C#✓ Tested
Calculate the number of calendar days between dates
C#: Subtract DayNumber values when the inputs are calendar dates.
C#✓ Tested
Call a library function
C#: Use a standard absolute-value function with a small negative number.
C#✓ Tested
Check a literal prefix with ordinal comparison
C#: Choose StringComparison.Ordinal when a prefix is a protocol token rather than culture-dependent text.
C#✓ Tested