FIND YOUR NEXT FEW LINES

Results for “Structures & function interfaces”

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

135 snippets foundClear filters
C#Collections & data structures

Process a FIFO queue

C#: Queue removes elements in the order they were enqueued.

C#✓ Tested
C#Collections & data structures

Process items by numeric priority

C#: PriorityQueue removes the item with the smallest priority value first.

C#✓ Tested
PythonFunctions & error handling

Raise and catch a domain-specific exception

Python: Give a validation failure its own exception type so callers can handle it narrowly.

Python✓ Tested
C#Collections & data structures

Remove matching items from a mutable list

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

C#✓ Tested
PowerShellFunctions & parameter validation

Return a collection as one pipeline object

PowerShell: The unary comma prevents the returned array from being enumerated at this boundary.

PowerShell✓ Tested
Bash ScriptsFunction scope & composition

Return a value through a named output variable

Bash Scripts: A Bash nameref can update a caller-supplied variable without command substitution.

Bash Scripts✓ Tested
Bash ScriptsFunction scope & composition

Return an array through a nameref

Bash Scripts: Assign through a nameref to preserve array element boundaries.

Bash Scripts✓ Tested
PowerShellFunctions & parameter validation

Run cleanup after a caught exception

PowerShell: Use finally for cleanup that must occur after either success or failure.

PowerShell✓ Tested
PythonFunctions & error handling

Run cleanup around a custom context

Python: Use try/finally inside a contextmanager so cleanup runs even on failure.

Python✓ Tested
C#Collections & data structures

Search a sorted array efficiently

C#: Array.BinarySearch requires an array sorted with the same comparison rules.

C#✓ Tested
RustFunctions & data types

Store data in an enum variant

Store data in an enum variant in a complete Rust program using the standard library.

Rust✓ Tested
C#Collections & data structures

Use a last-in first-out stack

C#: Stack is useful for reversible traversal and other nested operations.

C#✓ Tested