1 of 32 Images from Africa. 2 of 32 My little Haitian friend Antoine (1985)

Post on 01-Apr-2015

217 views 0 download

Tags:

Transcript of 1 of 32 Images from Africa. 2 of 32 My little Haitian friend Antoine (1985)

1 of 32

Images from Africa

2 of 32

My little Haitian friend Antoine (1985)

3 of 32

Solid Terrain Models

http://www.stm-usa.com/

4 of 32

3D Touch Table

6 of 32

Overview

Variables & ExpressionsBasic C# SyntaxCommentsDeclaring & initializing variables

Flow controlBoolean logicBranching & looping

Advanced typesenum, struct, Array

Type conversionsFunctionsVariable scope

7 of 32

Basic C# Syntax

8 of 32

Comments

//, ///, /* */

9 of 32

Declaring & Initializing variables

<type> <name>;<name> = <initial_value>;

OR<type> <name> = <initial_value>;

10 of 32

Types – esp. Value

Apart from bool, char,& enum, value types havea range of numbers theysupport (p. 37)

Type Range

byte 0 to 255

sbyte -128 to 127

short -32768 to 32767

int -2147483648 to2147483647

11 of 32

For real numbers …

12 of 32

Most commonly used types

int

string

double

bool

char

13 of 32

Variable names & initial values

<type> <name> = <initial_value>;

Variable namesCannot

Be a C# keywordBegin with a number or special char except _ and @Contain chars like -, ‘, etc)

ShouldBe camelCaseDescribe the content

Initial values0 for numbers or what makes sense for appstring.Empty / “” for strings, etc.

14 of 32

Expressions

<variable> = <operand> <operator> <operand>

// x = x + 1, z = x + 1// x = x + 1, z = x// x = x - 1, z = x – 1// x = x - 1, z = x

p. 46, 47 in Watson et al.++x add before expression evaluatedx++ add after expression evaluated

15 of 32

Overview

Variables & ExpressionsBasic C# SyntaxCommentsDeclaring & initializing variables

Flow controlBoolean logicBranching & looping

Advanced typesenum, struct, Array

Type conversionsFunctionsVariable scope

16 of 32

Boolean Logic

17 of 32

Branching with if

18 of 32

Branching with switch

19 of 32

Looping with for

20 of 32

Looping with while

21 of 32

Looping with do

22 of 32

Interrupting loops

breakExit from loop

continueReturn to top of loop

returnExit from loop & containing function

23 of 32

Overview

Variables & ExpressionsBasic C# SyntaxCommentsDeclaring & initializing variables

Flow controlBoolean logicBranching & looping

Advanced typesenum, struct, Array

Type conversionsFunctionsVariable scope

24 of 32

Advanced types – enum

To constrain the possible values for a variableDeclared at same level as classPlain text names associated with number

25 of 32

Advanced types – struct

A custom, multi-valued, type that can have functions

Declared at same level as classCan contain value types (int, long, double, etc) and strings

26 of 32

Advanced types – Array

Making it easier to create/access groups of values of the same type

27 of 32

Overview

Variables & ExpressionsBasic C# SyntaxCommentsDeclaring & initializing variables

Flow controlBoolean logicBranching & looping

Advanced typesenum, struct, Array

Type conversionsFunctionsVariable scope

28 of 32

Type conversions

Types with smaller range can be implicitly converted to types with larger rangeOther types MAY be explicitly converted target_type outvar = (target_type) variableName

29 of 32

Functions: Defining and calling

Syntax for defining functions: [scope] [static] return_type name ([params]){ // C# statements [return [return_value]];}

0 or more params are declared like variables and comma separated.

30 of 32

Params by ref and by value

31 of 32

Variable Scope

32 of 32

Funny if it wasn’t true

Air Transat ad

My version