The snippet library.
Small, practical examples. Search by task or narrow things down below.
Name a value that stays fixed
C#: Use a constant declaration or the language’s constant naming convention for a fixed limit.
C#✓ Tested
Print a number with two decimal places
C#: Format a small decimal value consistently for display.
C#✓ Tested
Read one character from ASCII text
C#: Use a valid zero-based index to read the first character.
C#✓ Tested
Read the beginning of a text value
C#: Extract or display the first three ASCII characters from a known nonempty string.
C#✓ Tested
Read the first collection element
C#: Access index zero only after establishing that the collection is nonempty.
C#✓ Tested
Repeat a fixed number of times
C#: Use a counted loop to print three numbered steps.
C#✓ Tested
Repeat while a condition holds
C#: Count down while a positive number remains, updating the loop variable on each iteration.
C#✓ Tested
Replace one collection element
C#: Update an existing element at a known valid index.
C#✓ Tested
Require two conditions to be true
C#: Combine a lower and an upper bound to check whether a value is in range.
C#✓ Tested
Run your first program
C#: Start with a complete program that prints one line. Follow the run instructions below.
C#✓ Tested
Store a value in a named variable
C#: Give a value a descriptive name and print it.
C#✓ Tested
Update a running count
C#: Change a variable after its initial value has been assigned.
C#✓ Tested