Glossary
125 terms from C# Basics, in plain words, each with the chapter that teaches it.
#
- .NET
- The free Microsoft platform that C# programs run on. It provides the runtime and a large library of ready-made code, such as the code that prints text.
- ?. and ?? (null-conditional and null-coalescing operators)
- `?.` reads a property only if the reference isn't null and gives null otherwise. `??` supplies a fallback value when the left side is null, as in `tea?.Price ?? 0m`.
A
- Argument
- A value you pass when calling a method. Arguments fill the method's parameters in order, or by name, as in `LineTotal(3, 4.75m)`.
- Array
- A fixed-length collection of values of one type, written like `decimal[]`. Its size can't change after it's made.
- Assigning
- Storing a new value in an existing variable with `=`, without repeating the type, as in `cups = 5;`. The `=` means "store this value", not "is equal to".
B
- bash
- A common kind of terminal shell, a program that reads the commands you type and runs them. In examples, a line starting with `$` is a command to type, without the `$`.
- Block
- A group of lines inside braces `{ }`, such as the lines an `if` or a loop runs. Variables declared inside a block exist only within it.
- bool
- A type that holds only `true` or `false`. Every comparison, such as `total >= 50`, gives a `bool`.
- break
- A keyword that leaves a loop or a `switch` at once. In a `switch`, each case must end by leaving it, usually with `break`.
- Build
- Turning source code into a program the computer can run. If the compiler finds a mistake, the build fails and tells you where.
C
- C#
- A widely used programming language, pronounced "C sharp". It is used for websites, online shops, desktop apps and games, and its programs run on .NET.
- C# Dev Kit
- Microsoft's extension for VS Code that colors your C# code, underlines mistakes as you type, and suggests names.
- camelCase
- The C# naming style for variables: start with a small letter and capitalize each later word, like `bagPrice`.
- case sensitive
- Capital and small letters count as different. In C#, `Console` is known but `console` is not.
- Cast
- Writing a type in parentheses, such as `(int)pounds`, to convert a value. Converting a `double` to an `int` this way cuts off the fraction rather than rounding.
- catch
- A block that handles a particular type of exception thrown inside the matching `try` block. The program then carries on after it.
- char
- A type that holds one character, written in single quotes like `'L'`.
- Class
- A blueprint for your own type that bundles data with methods. Objects built from a class can change, like a loyalty card gaining stamps.
- Collection expression
- Square brackets that create an array or list from values, such as `[3.25m, 4.75m]`, or an empty list with `[]`.
- Command
- One instruction to the computer, typed on one line in the terminal and run when you press Enter.
- Comment
- A note for people written after `//` on a line. C# ignores it.
- Common exception types
- Named exceptions for common mistakes: `FormatException` (text isn't a number), `OverflowException` (number too big for an `int`), `DivideByZeroException` (int divided by 0), `ArgumentException` and `ArgumentOutOfRangeException` (a value passed in is wrong or out of range), `IndexOutOfRangeException` (an index that doesn't exist), `KeyNotFoundException` (missing dictionary key), `InvalidOperationException` (e.g. `First` finds nothing) and `NullReferenceException` (a dot on null).
- Comparison operators
- Six operators (`==`, `!=`, `<`, `>`, `<=`, `>=`) that compare two values and give a `bool`. One `=` stores a value; two `==` compare.
- Compiler
- The program that checks your source code and translates it into instructions the computer can run. If it finds a mistake, the build fails and it reports where.
- Compound assignment (+=, -=, ++, --)
- Short forms that change a variable based on its own value: `stamps += 2` means `stamps = stamps + 2`, and `stamps++` adds 1.
- Concatenation
- Joining strings together with `+`, such as `first + " works in service"`.
- Console
- The built-in type for the terminal window. `WriteLine` and `Write` print text, and `ReadLine` waits for the user to type a line.
- const
- A keyword that makes a value that can never be assigned again, such as `ShippingPerBag`. Constants start with a capital letter and keep each price or rule written in one place.
- Constructor
- A method with the class's name and no return type that runs once when `new` creates an object. It sets the object's starting values.
- continue
- A keyword that skips the rest of the current pass of a loop and goes on to the next pass, such as skipping a cancelled order.
- Counting pattern
- Counting how often things appear by using each thing as a dictionary key and its count as the value: store 1 the first time, then add 1 each time after.
- Currency format (:C)
- A format specifier written after a colon in braces. `:C` shows money with a currency sign, thousands separators and two decimals, following the computer's region setting. Others are `:F2` (two decimals) and `:N0` (thousands separators).
D
- Debugger
- A VS Code feature that lets you watch a program run one line at a time. A breakpoint is a red dot beside a line where the program pauses so you can read each variable, and Step Over (F10) runs that line and pauses again.
- decimal
- A type for exact decimal fractions, used for money because it avoids the tiny rounding errors of `double`. Its number literals end in `m`, as in `4.75m`.
- Declaration
- Creating a variable by giving its type, a name, `=` and a starting value, such as `int cups = 3;`.
- Deconstruction
- Splitting a pair into two named variables at once, as in `foreach (var (name, cost) in menu)`.
- Default value
- A value given to a parameter with `=` so callers may leave the argument out, as in `decimal perBag = 4.00m`. Parameters with defaults go last.
- Dictionary
- A collection that stores key-value pairs, so you look up a value by its key, such as a price by drink name. Each key appears once.
- dotnet (command)
- The command-line tool that comes with the SDK. `dotnet run` builds and runs a program, and `dotnet new console -o Name` makes a new project.
- double
- A type for fractions stored in binary, suited to measurements. Most fractions are very slightly off, so it is not used for money.
E
- else if
- Parts added to an `if` to test further conditions. C# runs the first block whose condition is true and skips the rest.
- enum and DateTime
- An `enum` is a type with a fixed list of named values, such as `Roast.Light`. `DateTime` is a type that holds a date and a time of day.
- Error code (CS####)
- The code in a compiler error message, such as `CS1002`, which you can search for online. The message also gives the file, line and column.
- Escape sequence
- A backslash and a letter inside a string, such as `\n` for a new line, `\t` for a tab or `\"` for a double quote.
- Exception
- An object describing a problem at run time. If nothing catches it, the program stops and prints its type, message and stack trace.
F
- Field
- A plain variable held inside a class, such as `private int visits;`. Fields are usually private, with properties used for what outside code needs.
- File-based app
- A program written as a single `.cs` file and run directly with `dotnet run hello.cs`, with no project folder needed. This feature is new in .NET 10.
- Finally
- A block after the `catch` blocks that always runs, which suits clean-up work.
- First / FirstOrDefault
- LINQ methods that return the first item passing a test. `First` throws if none matches, while `FirstOrDefault` returns null or 0 instead.
- for loop
- A loop used when you know how many times to repeat. Its parentheses hold a start, a condition to keep going and a step.
- Foreach loop
- A loop that runs its block once for each item in a collection, storing the item in the variable you name.
G
- Generic
- A type that takes another type in angle brackets, such as `List<string>`, which says what the collection holds.
- Get-only and private set properties
- Property forms that control who may change a value. `{ get; }` is set only in the constructor, `{ get; private set; }` only by the class's own code, and `{ get; set; }` anywhere.
I
- if statement
- A statement that runs its block only when a condition in parentheses is true. An optional `else` block runs when it is false.
- Index
- The position of an item in a string, array or list. It starts at 0, so the last index is `Length - 1`.
- int
- A type for whole numbers. `Int32` is .NET's name for `int`.
- Integer division
- Dividing two `int` values gives an `int` and throws the fraction away, so `7 / 2` is 3. Make one number a `decimal` to keep the fraction.
K
- Key / Value
- In a dictionary, each key leads to one value, such as the drink name "latte" leading to 4.75. `Keys` and `Values` hold all of one side, and `ContainsKey` tells you whether a key is present.
L
- Lambda
- A tiny method written in place, such as `item => item.Price < 4m`. The parameter is left of the arrow `=>` and the value to work out is on the right. LINQ calls it once per item to test or pick a value.
- LINQ
- A set of methods such as `Where`, `Select` and `Sum` that filter, change, sort and total any list, array or dictionary. It needs `using System.Linq;`, which `dotnet` adds for you.
- List
- A collection that can grow and shrink, such as a shopping cart. You use `Add`, `Insert`, `Remove` and `RemoveAt` to change it.
- Local function
- What C# calls a method written among top-level statements. A `static` one can't use top-level variables.
- Logical operators (&&, ||, !)
- `&&` means "and" (both sides true), `||` means "or" (at least one side true) and `!` means "not" (flips true and false). They combine conditions.
- long-term support (LTS)
- A version of .NET that receives updates and fixes for an extended period, which makes it a safe choice for lasting work. .NET 10 is an LTS version, supported until November 2028.
- Loop
- Code that repeats a block while a condition is true. If nothing makes the condition false, it runs forever and you press Ctrl+C.
M
- Math.Round
- A method that rounds a number to the number of places you give, such as `Math.Round(share, 2)`.
- Method
- A named block of code that you write once and call whenever you need it. It can take parameters and return a value.
N
- named arguments
- Arguments written as `name: value`, which are easier to read and can come in any order, as in `Shipping(perBag: 3.50m, bags: 6)`.
- new
- A keyword that makes an object from a class or record, such as `new Order(1)`. Also used with exceptions, arrays and `new()` for collections.
- null
- "No value at all": a reference that points at no object. Using a dot on a null reference crashes with `NullReferenceException`.
- nullable type (?)
- A type followed by `?`, such as `string?` or `MenuItem?`, marks that its value may be null.
O
- Object
- A thing built from a class with `new`. Each object has its own copy of the data, like each customer's loyalty card.
- out
- Marks a parameter that a method fills in for you, since a method can return only one value. `TryGetValue` and `TryParse` use it.
- Overloading
- Giving two methods the same name with different parameters. It is why `Console.WriteLine` accepts a string, an `int` or a `decimal`.
- override
- A keyword saying you are replacing the version of a method every object already has, as with `ToString`.
P
- Parameter
- A variable in a method's parentheses that receives an argument when the method is called.
- Parse
- Methods that convert text into a number. If the text isn't a number, they throw an exception such as `FormatException`.
- Program
- A list of instructions for a computer. You write it as text called source code in a programming language.
- Project
- A folder with a `.csproj` settings file and one or more `.cs` files, used for bigger programs. `dotnet new console` creates one.
- Prompt
- The text a terminal displays at the place where you type a command. In examples, `$` stands for the prompt, so you don't type it.
- Property
- A named value on an object, read with a dot and no parentheses, like `card.Owner` or `email.Length`.
- public, private
- Access keywords. `public` members can be used from anywhere, while `private` ones only inside their own class, which protects data from mistakes elsewhere.
R
- Record
- A short type for fixed data, such as a menu item's name and price. It prints nicely, compares by value, and `with` makes a changed copy.
- Reference
- What a class variable holds: it says where the object is, rather than being the object. Copying the variable copies the reference, so both names point at one object.
- Remainder (%)
- The `%` operator gives what is left after dividing, so `7 % 2` is 1. It is handy for tests like every 10th drink being free.
- return
- A keyword that ends a method and hands a value back to the caller. In top-level statements, `return` ends the whole program.
- Runtime
- The part of .NET that runs your built program and supplies a large library of ready-made code.
S
- Scope
- The part of a program where a variable exists. A variable declared inside a block, or a method's own variables, can't be used outside it.
- SDK
- The runtime plus the tools for writing programs, including the compiler and the `dotnet` tool. It is what you install.
- Sequence
- What most LINQ methods give back: a series of items that isn't a list or array yet. Finish with `ToList()` or `ToArray()`, or loop over it with `foreach`.
- Signature
- The first line of a method: its return type, name and parameters.
- Sort / Reverse
- `Sort()` puts a list in order, smallest or alphabetically first, and `Reverse()` flips it. For an array, use `Array.Sort(a)`. Both change the collection itself.
- Source code
- The text instructions you write in a programming language, which the compiler turns into a runnable program.
- Stack trace
- The list of methods that were running when an exception happened, newest first. Start fixing at the line that names your own file.
- Statement
- One instruction in a program. C# needs a semicolon at the end of every statement.
- static
- Marks a method that belongs to the program itself rather than to an object. A static method sees only its own variables and what you pass in.
- String
- A piece of text, written in double quotes. String methods never change the original; they give back a new string.
- String interpolation
- Putting `$` before a string so values and expressions in braces are filled in, such as `$"{cups} cups"`.
- String methods
- Built-in actions on strings such as `Trim` for removing end spaces and `IndexOf` for finding where text starts. `Length` is a property giving the number of characters.
- string.Join / Split
- `Split` cuts a string into an array wherever it finds a character like a comma. `string.Join` glues items back into one string with text between them.
- StringComparison.OrdinalIgnoreCase
- Used with `string.Equals` to compare text while ignoring capitals. `string.IsNullOrWhiteSpace` checks for empty or all-space text.
- Sum / Count / Average / Min / Max / Any / All
- LINQ methods that answer a question about a whole list in one call. `Any` asks whether at least one item passes, and `All` whether every item does.
- switch
- A statement that compares one value against a list of fixed choices. C# jumps to the matching `case`, which ends with `break`, and `default` runs when nothing matches.
T
- Terminal
- A window where you type commands instead of clicking. You run your programs from it.
- this
- Inside a class, the object a method was called on. `this.Stamps` is the same as `Stamps`, and you need it only when a parameter has a property's name.
- throw
- A keyword that stops the method and sends an exception to its caller. You make the exception with `new`, as in `throw new ArgumentException("...")`.
- ToList / ToArray
- LINQ methods that turn a result sequence into a `List` or an array. Without them, LINQ results aren't lists yet.
- Top-level statements
- Lines that run from top to bottom with no wrapping class or Main method. Classes and records go after them at the end of the file.
- ToString
- A method that controls how an object prints. Without it, `Console.WriteLine(card)` prints only the type's name.
- try
- A block holding code that might fail. If it throws an exception, C# jumps to the matching `catch` block.
- TryGetValue
- A dictionary method that checks for a key and reads its value at once. It returns true or false and passes the value back through an `out` variable.
- TryParse
- Converts text to a number and returns true or false instead of throwing. The number comes back through an `out` variable, which suits checking typed input.
- Type
- The kind of value a variable holds, such as `int` or `string`. A variable keeps its type.
U
- using
- A line that makes a group of types or methods available, such as `using System.Linq;`. `dotnet` adds common ones for you.
V
- Value equality
- Records with the same values are equal when compared with `==`. Class objects are equal only if they are the very same object.
- var
- A keyword that lets C# work out a variable's type from its value. The type still never changes.
- Variable
- A named place that holds a value, created with a declaration. It has a type and a name.
- Verbatim string
- A string with `@` in front in which backslashes are just backslashes, which suits Windows file paths.
- void
- The return type of a method that does a job, like printing, but hands nothing back.
- VS Code
- A free code editor from Microsoft that you use with the C# Dev Kit extension to write and run programs.
W
- Warning
- A message milder than an error that points out something odd, such as a value you never use. The program still runs.
- Where / Select / OrderBy
- LINQ methods: `Where` keeps items that pass a test, `Select` turns each item into something else, and `OrderBy` and `OrderByDescending` sort. `ThenBy` breaks ties.
- while loop
- A loop that checks its condition, runs the block if true, then checks again. `while (true)` never stops on its own, so it suits stopping with `break`.
- Width
- A comma and a number after a value in braces pad it with spaces to that many characters. Positive aligns right and negative aligns left, as in `{price,8:C}`.
- with
- Makes a changed copy of a record, since the original can't change, as in `latte with { Price = 4.00m }`.