Variables & Types

2. Variables & Types#

Programs store and transform data. This chapter introduces the fundamental building blocks: naming and storing values, the types those values can have, how to compute with them, and how to read input and display results.

Why this chapter matters

Everything a program does involves data. Before you can write useful programs you must understand:

  • how variables hold values in memory

  • what types C# offers and when each is appropriate

  • how arithmetic and string operations work

  • how to interact with the user through the console

Learning goals

By the end of this chapter, you should be able to:

  • declare and initialize variables of numeric, boolean, and string types

  • apply arithmetic and string operators correctly

  • convert between types safely using casting and Parse

  • read user input with Console.ReadLine and display results with Console.WriteLine

Chapter flow