Variables

In computer programming, a variable is a named storage location in a program's memory where data can be stored, retrieved, and manipulated. Variables are fundamental to programming and are used to hold and manage data of various types, such as numbers, text, and more complex structures. To declare variables, you have to specify a data type ->

string message;

With the code above, the variable is set to null which basically means the absence of value. Null is used when a variable does not hold a value. It also is one of the most annoying errors for beginners.

string message = "Hello World";

Now the variable message is set to the value of Hello World

Data Types

In C#, data types are used to define the type and size of data that a variable can hold. C# is a statically typed language, which means that you must declare the data type of a variable before using it. Here are some of the common data types in C#.

Numeric Types

  • int: A number without decimals.
  • float: A number with 7 decimal digits of precision.
  • double: A number with 15 decimal digits of precision
  • Boolean Types

  • bool: True/False value
  • Reference Types

  • Class
  • Array
  • String: Alphanumeric sequence of characters.
  • Starting our Project: Bank Simulation

    To start off with this project, I will start by making some variables. For a bank account, we need the account holder's name, their age, and the starting balance of their account. Let me do that in C#.

    string name = "John Doe";
    int age = 13;
    double balance = 500.00;

    Next Section: Methods