C# Programming

Foundational Concepts for Objects

What is a Computer Program?

A computer program is a set of instructions for manipulating information.

  • Information is central to computer programs

  • Computer programs use Instructions to manipulate information

Variables, Values and Data Types

  • A Value is a piece of information

  • A Variable is an identifier for a piece of information

    • Think of it as a "container"

  • A Data Type describes information

    • How much memory to use

    • How to interpret the bits/bytes in memory

Visualizing Data in Memory

Data in memory is binary (1's and 0's)

010101000101010010100111110100011010101100101110101011100010101011010101101010010110101101

A variable refers to a block of memory. Imagine that block as a box.

Value Type vs. Reference Type

A Value Type stores its value at the memory address directly associated with the variable name.

int answer = 42; 

Value Type vs. Reference Type

A Reference Type stores the memory address of where the value is stored.

string name = "Stew Dent";

Reference Types - null

null refers to memory address zero (which doesn't exist)

Die fuzzyRedDie = null;

Reference Types - Instance

new instantiates an object based on the data type

fuzzyRedDie = new Die(20);

Rules for Variables/Values/Data Types

The following rules are applied to all variables, values and data types.

  • Any value stored in a variable must be of the same data type as the variable.
  • Variables must be declared before they can be used.
  • A variable's data type can only be declared once.
  • Each variable can only hold one value at a given time.
  • Each variable must have a distinct name.

The End