Chapter 2: Integers and Doubles

Numbers are everywhere in programming. A game tracks your score. A banking app calculates interest. A weather service reports temperature. A fitness tracker counts your steps. Behind each of these is a program working with numeric data.

But not all numbers are the same. Some are whole: 42 points, 7 items in your cart, 3 login attempts. Others have decimal parts: 98.6 degrees, $19.99, a 3.75 GPA. This distinction matters because computers store these two kinds of numbers differently, and choosing the wrong one causes problems.

This chapter introduces C#‘s two main numeric types: integers for whole numbers and doubles for decimals. We will start by understanding what these types are and how C# stores them. Then we will learn to compute with them, combine numeric comparisons with control flow, define reusable numeric methods, and group related numeric data into structs.

Chapter Sections

  1. Data and Memory: How C# represents numbers and how we store them
  2. Computation: How we transform numeric values through arithmetic and comparison
  3. Control Flow: How numeric comparisons drive branching, loops, and input validation
  4. Methods: How we package numeric computations into named, reusable methods
  5. Custom Types: How we group related numeric data into structs

We begin with Section 1 - Data and Memory: how does C# represent numbers?