Glossary
121 terms from C# Beyond the Basics, in plain words, each with the chapter that teaches it.
#
- .csproj file
- The XML file holding a project's settings, such as the target .NET version, nullable setting and references to other projects or packages.
A
- abstract
- A keyword on a class means you can't create it directly with `new`, as with `Product`. On a method it means there is no body, and every derived class must supply one with `override`.
- ahead-of-time compilation (AOT)
- A way of building a program into machine code before it runs, rather than while it runs. File-based C# apps use it by default, which turns off the reflection that `JsonSerializer` uses to discover a type's properties, so such apps need `#:property PublishAot=false` to serialize JSON.
- anonymous type
- A small object made with `new { Cafe = ..., Total = ... }` that has no type name you can write. Store it with `var` and use it inside one method.
- args
- The words typed after a program's name, given to the program as a `string[]`. For example, running `sell DEC-12 3` gives the program three items: `sell`, `DEC-12` and `3`.
- Arrange, Act, Assert
- The three parts of a typical test: set up the objects, call the code being tested, then check the result.
- ASP.NET Core
- .NET's framework for building websites and web APIs, covered in the next book for the Kettle & Crane shop.
- Assert
- xUnit's static class of checks. A test fails when a check does not hold, for example `Assert.Equal(11.75m, price)`. Put the expected value first.
- async
- `async` marks a method that uses `await` to wait for a `Task` without blocking the program. Other work can run while it waits, and the method continues when the result arrives.
- async void
- An async method that returns `void` instead of `Task`. Nothing can await it or catch its errors, so avoid it and return `Task`.
- attribute
- Extra information in square brackets above a type or member, such as `[Fact]` or `[JsonPropertyName("on_hand")]`. Tools and libraries read it and act on it.
- await using
- The async form of `using`: it closes a stream asynchronously when the variable goes out of scope, as in `LoadAsync`.
B
- base
- In a derived class, `: base(name, price)` runs the base class constructor first, and `base.Describe()` calls the base class's version of a method.
- base class
- A base class (such as `Product`) holds code shared by others. A derived class (such as `CoffeeBag`) inherits it and adds its own parts.
- blocking
- Code that sits waiting for something slow, such as a disk or server, so that nothing else can happen on that thread. Async code avoids this.
C
- CancellationToken
- A signal passed to async code that says "stop now". A `CancellationTokenSource` makes the token and can cancel it after a set time, which gives a timeout.
- class library
- A project of reusable types that doesn't run on its own. Programs and tests reference it, like `Shipping.Core`.
- closure
- A lambda together with the outside variables it captures. The lambda keeps a link to the variable itself, not a copy, so later changes to it are seen.
- collection expression
- Square brackets that build a list or array in one step, such as `List<decimal> prices = [16m, 15m];`. An empty `[]` makes an empty collection.
- constraint
- A `where` rule that says what a type parameter must be able to do, such as `where T : IHasSku`. It lets generic code use those members.
- CSV
- A text format with one row per line and values separated by commas, like Sam's `orders.csv`. Quoted fields containing commas need a library such as CsvHelper.
- culture
- The computer's regional settings, such as which character is the decimal point. `CultureInfo.InvariantCulture` always uses `.`, so data files parse the same on every computer.
D
- default(T)
- The empty value of a type: 0 for numbers and `null` for classes. In generic code you write it as `default(T)` or just `default`.
- deferred execution
- A LINQ query doesn't run when you write it, but when something walks through its results. Items added to the list in between appear in the result unless you call `ToList()` first.
- delegate
- A variable that holds a method, so you can call it later or swap in another method. `Func` and `Action` are ready-made delegate types.
- dependency injection
- A technique where a class is handed the interfaces it needs, such as an `IStore<T>`, instead of creating them. You can then swap in a fake in tests. It is covered in the next book.
- directive (#:)
- A line starting with `#:` in a file-based app that sets project settings, placed before any code, such as `#:property PublishAot=false`.
- discard
- The `_` pattern, which matches anything you don't need to name. It is usually the last arm of a switch expression, meaning "everything else".
- dotnet add package
- Command that downloads a NuGet package and adds a `PackageReference` for it to the project's `.csproj`.
- dotnet add reference
- Command that lets one project use the public types of another, such as the console app using `Shipping.Core`. It adds a `ProjectReference` to the `.csproj`.
- dotnet new
- Command that creates a new solution or project from a template, such as `sln`, `classlib`, `console` or `xunit`.
- dotnet pack
- Command that builds a project into a `.nupkg` NuGet package that others can add.
- dotnet run
- Command that builds and runs a project. Words after `--` go to your program as `args`, and `--project` names which project to run.
- dotnet sln add
- Command that adds one or more projects to a solution file so they can be built together.
- dotnet test
- Command that builds the projects, finds and runs every test, and prints a summary of how many passed, failed and were skipped.
E
- EF Core
- A .NET library that saves your records in a database, using LINQ queries and async methods. It is covered in the next book.
- event
- A member that lets a class announce that something happened, like `LowStock` on `StockRoom`. Other code subscribes with `+=` and unsubscribes with `-=`, and only the class itself can raise it.
- EventHandler<T>
- A standard delegate type used by many .NET libraries for events. Subscribers receive both the sender object and the event data.
- expression-bodied member
- A short form for a method or property whose whole body is one value: `=> Price;` means `{ return Price; }`.
- extension method
- A static method in a static class with `this` before its first parameter, so you can call it like a member, as in `orders.TotalValue()`. LINQ's methods are extension methods.
F
- Fact
- The xUnit attribute that marks a method as a test. The test runner finds and calls every `[Fact]` method.
- fake
- A small class written for tests that stands in for a real one, such as `FakeRate` with a fixed price. It works because code depends on the interface, not the real class.
- file-based app
- A C# program that is a single `.cs` file run directly with `dotnet run`, with no project file. Settings go in `#:` directives at the top.
- file-scoped namespace
- A `namespace Kettle.Shipping;` line ending in a semicolon at the top of a file, which puts every type in that file into the namespace.
- Func and Action
- Ready-made delegate types. `Func<decimal, decimal>` holds a method that takes a decimal and returns one (the last type is the result), and `Action<string>` holds a method that returns nothing.
G
H
- HttpClient
- A .NET class for making web requests, such as `await client.GetStringAsync(url)` to download a page.
I
- IComparable<T>
- An interface promising a `CompareTo` method that says whether one item comes before, equal to or after another. Numbers and strings implement it, so `where T : IComparable<T>` lets generic code compare items.
- IDisposable
- An interface for objects that hold something that must be released, such as an open file. Its `Dispose()` method frees it, and `using` calls it for you.
- IEnumerable<T>
- "A sequence of T you can walk through with `foreach`." Lists, arrays and dictionaries implement it, and it is LINQ's input and output type.
- IGrouping
- One group produced by `GroupBy`: a sequence of the group's items plus a `Key` property.
- implement
- A class or record implements an interface by naming it after a colon and providing every member it lists as `public` members.
- ImplicitUsings
- A `.csproj` setting that adds common `using` lines automatically, such as `System` and `System.IO`, which is why `Console` and `File` work without them.
- inheritance
- Making a class from another class so it gets the other class's members, as `CoffeeBag : Product` does. A class can inherit from only one class.
- init
- A property accessor used in place of `set` that allows the value to be set only while the object is being made, in an object initializer.
- InlineData
- An xUnit attribute that supplies one row of arguments to a `[Theory]` test. The runner counts each row as its own test.
- interface
- A list of members that a type promises to provide, without saying how they work, such as `IShippingRate` with `Carrier` and `PriceFor`. Names start with `I` by habit.
- internal
- The default access for a type: visible only inside its own project. Another project can use a type only if it is marked `public`.
- iterator
- A method that hands back items one at a time with `yield return`, pausing between items. Like `Where`, it is deferred and runs only when something walks through its result.
J
- JSON
- A text format for data used by most web APIs: objects in braces with `"name": value` pairs and lists in square brackets.
K
- KeyNotFoundException
- The exception .NET uses for "no such key". `Inventory.Sell` throws it when the SKU isn't in the dictionary.
L
- lambda
- A short nameless method written with `=>`, such as `price => price - 2m`. It can be stored in a delegate or passed to a method, and can have a block body.
- LINQ
- A set of methods such as `Where`, `Select` and `OrderBy` for filtering, shaping and grouping sequences of data. Each takes a delegate such as a lambda.
- list pattern
- A pattern that matches an array or list item by item in square brackets, such as `["sell", var sku, var qty]`. `..` matches any number of items.
- local function
- A method written inside other code. Methods written below top-level code are local functions that can be called from anywhere in the file.
M
- method group
- A method's name used as a delegate, without parentheses, such as `rule = TenPercentOff`. With parentheses you would call the method instead.
- Minimal APIs
- An ASP.NET Core style that connects a web address to a lambda that answers requests. It is covered in the next book.
- Moq
- A library that creates fakes for you in tests, instead of writing fake classes by hand.
N
- namespace
- A named group of types, such as `Kettle.Shipping`, so two libraries can each have a `FlatRate` without clashing. A `using` line lets you use its types by short name.
- NuGet
- A package is a compiled library bundled for sharing, and NuGet is .NET's package system, hosted at nuget.org. Humanizer is one example.
- null-forgiving operator
- A `!` after a value tells the compiler "this isn't null, trust me" and hides the warning. It checks nothing at run time, so a wrong guess still crashes.
- null-state analysis
- The compiler following each `if`, `return` and assignment to work out where a variable may be null, and warning before you use a possible null.
- nullable reference types
- A feature where `string` can never be null and `string?` can be, with compiler warnings when you use a possible null unchecked. Switched on with `<Nullable>enable</Nullable>`.
- NullReferenceException
- The error a program stops with when it follows a reference that holds null, for example using `.Name` on a missing item.
O
- object initializer
- Braces after `new()` that set properties by name, such as `new() { Name = "Rose City Pottery" }`. It is the only place `init` and `required` properties can be set.
- override
- A keyword that replaces a base class's `virtual` or `abstract` method in a derived class. `base.Method()` can still call the original.
P
- pattern
- A shape you test a value against: its type, a constant, a range, its properties or its items. Patterns are used with `is` and in switch expressions.
- polymorphism
- Calling one method through a shared type and getting each object's own behavior. Alex's loop calls `PriceFor` on an `IShippingRate`, and each rate runs its own version.
- positional record
- A record whose values in parentheses, such as `record FlatRate(string Carrier, decimal Price)`, automatically become properties and constructor parameters. A `with` expression copies it with changes.
- property pattern
- A pattern that tests an object's properties in braces, each with its own pattern, such as `{ OnHand: 0 }` or `{ Supplier: "Cascade Green Coffee", OnHand: > 20 }`.
- protected
- An access level between `public` and `private`: the class and its derived classes can use the member, but other code can't.
- public
- An access level that lets any code use the type or member, including other projects. Types in a class library must be `public` for the console app to use them.
Q
- query syntax
- A way to write LINQ that reads like SQL: `from o in orders where ... select o.Id`. It means the same as the method form.
R
- reference type
- A type such as a class, record, string or list. A variable of one refers to an object in memory, and null means it refers to nothing.
- relational and logical patterns
- Relational patterns compare, such as `< 1` or `>= 12`. The logical patterns `and`, `or` and `not` combine patterns, so `2 or 3` matches either number.
- relative path
- A relative path such as `"packing.txt"` is found from the working folder, the folder the terminal was in when the program started. An absolute path starts from the top of the disk.
- required
- A modifier on a property meaning every object initializer must set it when the object is made. Leaving it out is error CS9035.
- restore
- Downloading the packages a `.csproj` lists. `dotnet build` and `dotnet run` do it automatically.
S
- sealed
- A keyword before a class that stops anyone from deriving from it.
- SelectMany
- A LINQ method that flattens a sequence of sequences into one, such as turning a list of delivery routes into one list of cafés.
- serialize and deserialize
- Serializing turns objects into text such as JSON, and deserializing turns that text back into objects. `JsonSerializer.Serialize` and `Deserialize<T>` do each.
- SKU
- A short code that identifies a product, such as `DEC-12` for the 12 oz decaf at Kettle & Crane. It is often used as a lookup key to find an item in a list or catalog.
- solution
- A `.slnx` file that groups related projects, so one command can build or test them all.
- static class
- A class that holds only static members, so you call them on the class itself without creating an object, like `RateFinder.Cheapest`. Extension methods must live in one.
- Stopwatch
- A class from `System.Diagnostics` that measures elapsed time. `Stopwatch.StartNew()` starts one and `Restart()` sets it back to zero.
- stream
- A file read or written piece by piece. `StreamReader` and `StreamWriter` handle text a line at a time, and a stream must be closed, so you open it with `using`.
- switch expression
- A `switch` that picks a value rather than running statements: `x switch { pattern => result, ... }`. The first matching arm wins, so order matters.
- System.Text.Json
- The .NET library that turns objects into JSON and back, through `JsonSerializer.Serialize` and `Deserialize`. `JsonSerializerOptions` such as `WriteIndented` control the output.
T
- TargetFramework
- The `.csproj` setting naming the .NET version a project is built for, such as `net10.0`.
- Task
- .NET's representation of work that finishes later. A `Task` has no result, and a `Task<T>` will produce a `T`, like an order ticket you collect later.
- Task.Delay
- A method that returns a task that finishes after a set number of milliseconds, without blocking the program while it waits. It is often used to stand in for slow work, and it can take a `CancellationToken` so the wait can be cut short.
- Task.Run
- Starts heavy calculation on another thread and returns a `Task` to await. Async alone helps with waiting, not with calculation.
- Task.WhenAll
- `WhenAll` finishes when every task has, and returns their results in the order you passed them. `WhenAny` finishes as soon as the first task does. Starting tasks together and using `WhenAll` runs them at once.
- TaskCanceledException
- The exception thrown by methods such as `Task.Delay` when their `CancellationToken` is canceled.
- Theory
- An xUnit attribute for a test with parameters. It runs once for each `[InlineData]` row, and each row counts as its own test.
- thread
- A path of execution in a program. `Task.Run` moves work to another thread so the current one isn't tied up.
- ToDictionary
- A LINQ method that builds a dictionary from a key and a value for each item. It throws if two items share a key.
- ToList
- LINQ methods that run a query now and store the answers in a list or array. Use them for a fixed snapshot, or before walking a slow query more than once.
- top-level code
- Statements written directly in a file with no `Main` method, as in `Program.cs` or a file-based app. They can use `await` directly.
- TryGetValue
- A dictionary method that looks up a key and returns true if found, filling an `out` variable with the value. `Inventory.Sell` uses it to check a SKU exists before changing anything.
- tuple
- A small group of values in parentheses with no declared type, optionally named, such as `(Cafe: "Hearth", Total: 172m)`.
- tuple pattern
- A pattern that tests several values at once, one pattern per value, such as `("FedEx", > 10)`.
- type parameter
- The placeholder type in a generic, such as `T` in `Last<T>`. It is replaced by a real type each time the method or class is used.
- type pattern
- A pattern like `rate is WeightRate w` that checks an object's real type and, if it matches, gives you a variable of that type.
U
- unit test
- A small method that calls one piece of code with known input and checks the result. You write it once and run it after every change.
- using declaration
- `using var x = ...;` calls `Dispose` on `x` when it goes out of scope, even after an exception. The `using` statement does the same at the end of its braces.
V
- virtual
- Marks a method that derived classes may replace with `override`, like `Product.Describe()`.
W
- when guard
- An extra condition after a pattern: the arm matches only if the condition is also true, as in `_ when item.OnHand <= item.ReorderAt => "LOW"`.
- with expression
- Copies a record and changes the properties you name, such as `item with { OnHand = 9 }`. The original record is untouched.
X
- xUnit
- The most used test library for C#, providing `[Fact]`, `[Theory]` and the `Assert` class. `dotnet test` finds and runs its tests.