Variables & Types

2. Variables & Types#

Programs store and transform data. This chapter introduces the fundamental building blocks of C#: naming values, choosing types, computing with expressions, and reading or displaying console data.

  • Variables: Names let programs store values and refer to them later.

  • Types: C# uses types such as int, double, bool, and string to define what each value can do.

  • Operators: Arithmetic, comparison, logical, and string operators let programs compute new values.

  • Console I/O: Console.ReadLine and Console.WriteLine connect a program to user input and output.

These ideas are the raw materials for every later C# program: once you can name data, choose its type, transform it, and show a result, you can begin building useful workflows.

Video

C# variables ✖️ by Bro Code.

This video remains hosted on YouTube and is the property of its original creator or rightsholder; it is embedded here via YouTube’s official player for educational reference only.

Learning Objectives

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

  1. Declare and initialize variables of numeric, Boolean, and string types

  2. Choose appropriate C# types for common kinds of program data

  3. Apply arithmetic, comparison, logical, and string operators correctly

  4. Convert between compatible types using casts and parsing methods

  5. Read console input and display formatted output

Chapter Flow