week 1: getting dirty - part 1

23
Getting Dirty – Part 1 Jamshid Hashimi, CodeWeekend

Upload: jamshid-hashimi

Post on 07-Aug-2015

102 views

Category:

Technology


2 download

TRANSCRIPT

Getting Dirty – Part 1Jamshid Hashimi, CodeWeekend

Agenda

• Expressions, Types, and Variables• Control Statements - Selection• Control Statements - Loops• Methods• Namespaces• Introduction to Classes• Class Inheritance• Polymorphism

Expressions, Types, and Variables

• Variables: storage locations for data• int num = 428;

• C# is a strongly typed language. • All operations are based on variable Types

• C# simple types consist of:• Boolean Type• 3 numeric type: Integrals, Floating Point, Decimal• String

Expressions, Types, and Variables

• The Boolean Type• Declared by keyword: bool• Has two values: true or false

Expressions, Types, and Variables

• In C++, a value of type bool can be converted to a value of type int; in other words• false is equivalent to zero and true is equivalent to nonzero values.

• In C#, there is no conversion between the bool type and other types.

Expressions, Types, and Variables

• Integral Types• Number, either signed and unsigned and char type

Expressions, Types, and Variables

• Floating Point and Decimal Types• To represent real numbers

Expressions, Types, and Variables

• The String Type• A string is a sequence of text characters.• “This is a string example”• Some characters are not printable

Expressions, Types, and Variables

• Operands and Operators• Operand is a piece of information or data• Operator specifies what action should be done with the operand(s).• operandOne operator operandTwos

• Expressions• An expression is simply one or more operands and their associated operator

treated as a single entity.• answer = operand1 / operand2

Expressions, Types, and Variables

• Statements• In C#, a program statement is one or more expressions terminated by a

semicolon. • answer = operand 1 / operand2;

Expressions, Types, and Variables

Expressions, Types, and Variables

• solution = 2 + 3 * 4 + 5;• Overriding the default Precedence order• Solution = (2 + 3) * (4 + 5);

Control Statements - Selection

• If statements• An if statement allows you to take different paths of logic, depending on a

given condition.• There are two forms of OR:

• Regular OR (|) operator will evaluate both sub-expressions every time. • Conditional OR (||) will evaluate the second sub-expression only if the first sub-

expression evaluates to false.• There are two forms of AND:

• Regular AND operator will evaluate both expressions every time. • Conditional AND operator will evaluate the second sub-expression only when the first

sub-expression evaluates to true.

Control Statements - Selection

• Switch Statements• A type of selection control mechanism used to allow the value of a variable or

expression to change the control flow of program execution via a multiway branch.

• Break!• Go to!

Control Statements - Loops

• Learn the while loop• A while loop will check a condition and then continues to execute a block of

code as long as the condition evaluates to a boolean value of true.

• Learn the do loop• A do loop is similar to the while loop, except that it checks its condition at the

end of the loop.

Control Statements - Loops

• Learn the for loop• By using a for loop, you can run a statement or a block of statements

repeatedly until a specified expression evaluates to false.

• Learn the foreach loop• The foreach statement repeats a group of embedded statements for each

element in an array or an object collection.

Methods

• Methods are to split our logic into units• Name should be meaningful• Should be associated with the task• Parameters are to transfer information to and from method

attributes modifiers return-type method-name(parameters){

statements}

Methods

• Instance Methods• Static Methods• Pass by value• Pass by reference• this keyword

Namespaces

• Namespaces are C# program elements designed to help you organize your programs.• Also to avoid name conflicts

Introduction to Classes

• Classes are templates to objects• Constructors• Instance and Static methods, again!• Destructors

• To release the allocated resources

Inheritance

• Inheritance is one of the primary concepts of object-oriented programming. It allows you to reuse existing code.

Polymorphism

• It allows you to invoke derived class methods through a base class reference during run-time. • Sending the same message, getting the correct response

Thank You!