GetValueOrDefault on IReadOnlyDictionary
Look up a dictionary value with a fallback and know when to distinguish a missing key from a stored `null`.
CKTIS / C#
Programming syntax, operators and concepts. Find an explanation, explore an example and return to learning.
Look up a dictionary value with a fallback and know when to distinguish a missing key from a stored `null`.
`Environment.Exit(0)` ends the current process with a success status. Assigning to `Environment.ExitCode` only sets the status and lets the program continue.
End the entire process after printing a report and signal success with exit code `0`. Learn when returning from `Main` is the better choice.
Use `Func<bool>` to test signal classification rules and `Action<int>` to notify the caller after processing a unit.
Register factories with different service return types in a custom container, then use the same delegate type to filter and transform a sequence with LINQ.
Use a bool-returning delegate to filter items, a decimal-returning delegate to select amounts, and invariant formatting to render the total.
Use one delegate to report conversion success and another to update an accumulator. Throw an exception when the requested size is outside the allowed range.
Pass separate success and error delegates to `Match` with a shared return type. Use `FormattableString.Invariant` to format interpolation without relying on the current culture.
Distinguish three formatting contracts: looking up a service, intercepting a format item, and letting the value's own type produce the text.
Define the `Price.ToString` contract, pass numeric settings through to `decimal`, and change the decimal separator on a writable copy rather than on the original.
Create a view of text without copying it, search for an element or sequence, and print the matching slice through `Console.Out.Write` without creating a substring.
Use spans to search and compare existing text without copying it, then parse fields as `int` or `decimal` with explicit format rules.
Choose an explicit tie rule: round to the nearest value, but at an exact midpoint choose the result with the larger absolute value.
IEnumerable provides an enumerator, and IEnumerator tracks the position in a sequence. An explicit implementation satisfies the non-generic contract without duplicating iteration logic.
Enable nullable analysis and describe both outputs of a `Try*` method so the compiler knows that neither output is null on success.
Enable nullable reference annotations and compiler warnings. See how a null check affects flow analysis and why `string?` does not work the same way as `int?`.
Store behavior in variables and pass it as arguments: Action performs an operation, Func returns a result, and Predicate tests a condition.
Use `Array.Clone()` to create a separate array, then sort it in place with `Array.Sort` and a `Comparison<T>` delegate. The clone can still share element objects with the original.
Declare where an attribute is valid, select public instance properties, and distinguish attributes applied directly from those found through inheritance.
Choose the delegate for an event with or without data, and learn how to remove a handler when it is no longer needed.
Bind an argument to a delegate with partial application, see what a closure captures, and keep decimal rounding separate from culture-invariant formatting.
Use one delegate to calculate a decimal amount from a product and another to turn that amount into text with an explicit format.
Use `Func<T>` as a parameterless factory and `Action<T>` to reset a returned object in your own pool.
Read the ISO 4217 currency code for an explicit region and distinguish it from the region code and the symbol displayed next to an amount.