FIND YOUR NEXT FEW LINES

The snippet library.

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

25 snippets foundClear filters
C#Getting Started

Calculate a simple total

C#: Multiply a unit price by a quantity, then add a delivery fee.

C#✓ Tested
C#Getting Started

Call a library function

C#: Use a standard absolute-value function with a small negative number.

C#✓ Tested
C#Getting Started

Choose between two branches

C#: Use if and else to handle an available or empty stock count.

C#✓ Tested
C#Getting Started

Combine text with a name

C#: Construct a greeting from a fixed prefix and a stored name.

C#✓ Tested
C#Getting Started

Compare a value with a limit

C#: Turn a comparison into a readable yes or no result.

C#✓ Tested
C#Getting Started

Convert known numeric text to an integer

C#: Convert a trusted literal to an integer before adding. Validate external input before converting it.

C#✓ Tested
C#Getting Started

Count the items in a collection

C#: Read the collection’s length instead of hard-coding the loop limit.

C#✓ Tested
C#Getting Started

Divide using a fractional number

C#: Use a floating-point operand to preserve the fractional part of a division.

C#✓ Tested
C#Getting Started

Explain a calculation with a comment

C#: Keep the code executable while documenting why a fixed input is used.

C#✓ Tested
C#Getting Started

Find what remains after division

C#: Use the remainder operator to count items left after forming complete groups.

C#✓ Tested
C#Getting Started

Handle three possible outcomes

C#: Check high, normal and low values with an ordered conditional chain.

C#✓ Tested
C#Getting Started

Measure a short text value

C#: Read the length of an ASCII string. Non-ASCII text may use multiple code units or bytes depending on the language.

C#✓ Tested