FIND YOUR NEXT FEW LINES

The snippet library.

Small, practical examples. Search by task or narrow things down below.

125 snippets foundClear filters
C#JSON & binary formats

Read an optional JSON property safely

C#: Use TryGetProperty instead of throwing when an optional property is absent.

C#✓ Tested
C#Getting Started

Read one character from ASCII text

C#: Use a valid zero-based index to read the first character.

C#✓ Tested
C#Getting Started

Read the beginning of a text value

C#: Extract or display the first three ASCII characters from a known nonempty string.

C#✓ Tested
C#Getting Started

Read the first collection element

C#: Access index zero only after establishing that the collection is nonempty.

C#✓ Tested
C#Dates & precise numbers

Reject infinity and NaN

C#: Double.IsFinite distinguishes usable finite numeric inputs from special values.

C#✓ Tested
C#LINQ transformations

Remove duplicate records by a selected key

C#: DistinctBy keeps the first record for each key in encounter order.

C#✓ Tested
C#Collections

Remove duplicate values

Use LINQ Distinct and OrderBy for a sorted C# result.

C#✓ Tested
C#Collections & data structures

Remove matching items from a mutable list

C#: List.RemoveAll returns how many items it removed.

C#✓ Tested
C#Getting Started

Repeat a fixed number of times

C#: Use a counted loop to print three numbered steps.

C#✓ Tested
C#Getting Started

Repeat while a condition holds

C#: Count down while a positive number remains, updating the loop variable on each iteration.

C#✓ Tested
C#File operations & paths

Replace a path extension

C#: Path.ChangeExtension transforms a path string without moving or creating a file.

C#✓ Tested
C#Strings

Replace literal text

Replace every literal occurrence in a C# string.

C#✓ Tested