Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C#

Knowledge base — C#

Programming syntax, operators and concepts. Find an explanation, explore an example and return to learning.

Entries: 443

C#

GetValueOrDefault on IReadOnlyDictionary

Look up a dictionary value with a fallback and know when to distinguish a missing key from a stored `null`.

Advanced · C# 12 and .NET 8; later runtimes may add compatible features
C#

`Environment.Exit(0)` after printing a report

End the entire process after printing a report and signal success with exit code `0`. Learn when returning from `Main` is the better choice.

Basic · C# 12 and .NET 8; later runtimes may add compatible features
C#

Func delegates and invariant report formatting

Use a bool-returning delegate to filter items, a decimal-returning delegate to select amounts, and invariant formatting to render the total.

Advanced · C# 12 and .NET 8; later runtimes may add compatible features
C#

Delegates in `Match` and culture-invariant formatting

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.

Advanced · C# 12 and .NET 8; later runtimes may add compatible features
C#

MemoryExtensions.AsSpan and IndexOf: searching a text view

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.

Advanced · C# 12 and .NET 8; later runtimes may add compatible features
C#

Search, compare, and parse span views

Use spans to search and compare existing text without copying it, then parse fields as `int` or `decimal` with explicit format rules.

Advanced · C# 12 and .NET 8; later runtimes may add compatible features
C#

MidpointRounding.AwayFromZero with decimal.Round

Choose an explicit tie rule: round to the nearest value, but at an exact midpoint choose the result with the larger absolute value.

Advanced · C# 12 and .NET 8; later runtimes may add compatible features
C#

Non-generic IEnumerable and IEnumerator in System.Collections

IEnumerable provides an enumerator, and IEnumerator tracks the position in a sequence. An explicit implementation satisfies the non-generic contract without duplicating iteration logic.

Intermediate · C# 12 and .NET 8; later runtimes may add compatible features
C#

Action<T>, Func<T,TResult>, and Predicate<T> delegates

Store behavior in variables and pass it as arguments: Action performs an operation, Func returns a result, and Predicate tests a condition.

Intermediate · C# 12 and .NET 8; later runtimes may add compatible features
C#

Shallow array cloning and sorting with Comparison<T>

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.

Intermediate · C# 12 and .NET 8; later runtimes may add compatible features