Beginning C# Programming with Unity

Ch 1. Introduction

Hardware Organization

Hardware. Tangible components of a computer system or electronic device

  • Central Processing Unit (CPU). The part of the computer that executes instructions

    • U. Only thing a computer can do is execute instructions, one after another.

  • Memory. Holding place of data, programs, and instructions

    1. Main memory. Volatile data storage device

      • Random Access Memory (RAM). Volatile memory (storage that is erased when computer turns off) that stores information that can be change

      • Read Only Memory (ROM). Stores some permanent information that cannot be changed as the computer is running

      • Cache memory. Special extra-fast type of main memory that resides on the CPU chip rather than RAM chip

    2. Secondary memory. Non-volatile data storage device (ex. hard disk)

  • Input devices. Hardware devices used to provide input to the computer (ex: keyboard, controllers, microphones, etc.)

  • Output devices. Devices that provide output to the user of the computer (ex: computer monitor, printer, etc.)

Binary. 0’s & 1’s

Bus. Centralized communication mechanism for all hardware devices (Ex. forum)

Computer Software

Computer software. The set of instructions the computer will run on

Machine instruction

Programming languages. have both syntax and semantics

  • Syntax. The rules that determine the order of the words we include and the punctuation we use

  • Semantic. Computational meaning to valid strings

two types

editor.

Integrated Development Environment (IDE). A software application that consolidates all the essential tools that a developer needs to write, test, and debug software into a single, unified graphical interface

source code.

Interpreted languages

  • Interpreter. Converts the program one statement at a time and the CPU executes the instructions as they’re converted.

Compiled languages

  • Compiler. Converts the entire program into the machine instructions (check for syntax errors)

Common Intermediate Language (CIL). .NET instructions that aren’t specific to any particular CPU, making CIL portable to any machine

  • Common Language Runtime (CLR).

Writing and Running a C# Program

.cs file tells the people that the file is C#

Ch 2. Starting to Code

What Does a C# Program Look Like?

Statement. A complete line of code which can be executed for an effect

C#, object-oriented language

Classes.

.cs file

application class. runs the program

when items are listed in italics, the programmer (you) decides what goes there

when appear without itlatics, those words need to appear exactly as written

Keywords. Reserved word in a programming language that has a predefined meaning

Using Other Namespace and Classes

Namespaces & Classes. Collections of useful C# code that someone else has already written, tested, and debugged

the using directive. tells the compiler that you want access to the classes in the system namespace

Console class

Comments

Comment. Documentation within the source code

  • Class documentation comment. Documentation for other programmers within the source code

    • Syntax. /// <summary>

  • Line comment. Whole line ignored by the compiler

    • Syntax. //

  • Comment spanning several lines

    • Syntax. /* … */

Identifiers

Identifiers. A formal programming term for a word that can be used to name something

  • Case-sensitive, any length + any numbers + underscores, must start with letter

  • Ex. myVariable, apple_Price

The Main Method

Method. Parameterized computation of code that preforms a specific task (i.e. block, analogous to function)

main Method. Entry point for the application

  • static void main(string[] args)

Variables and Constants

Variable. Named storage location in the computers memory used to store data that can be accessed and modified as a program runs (visualize a box)

  • Syntax. int myVariable;

Constant. Immutable values known at compile time and don’t change during the life of the program

  • Syntax. const

Console Output

IO. Input & Output

  • Output. Displays data

    1. Console.Write

      • Outputs what you tell it to print on a line on the screen, then leaves the cursor on that line so we can print more on that line

    2. Console.WriteLine()

      • Moves cursor to the next line after printing what we tell it to

  • Input.