You are on page 1of 16

Event Driven Programming

Lecture 1
Variables
A name you give to a storage location in memory.

A constant is an immutable value whose value is known at the time of compilation.

Constants make our programs more safe by protecting unchangeable values from accidental
changes.

Declaring a variable:

type identifier;

type identifier= value;

const type identifier= value;

You should always initialize constant variables and you should initialize a variable before
using it.
Identifier Naming Rules
- Can’t start with a number
- Can’t contain whitespaces
- Can’t be a reserved keyword.

Naming Conventions :

CamelCase for local variables

PascalCase for constants


Primitive Data Types
Data Type Size (byte) .NET Type

byte 1 Byte

short 2 Int16

int 4 Int32

long 8 Int64

float 4 Single

double 8 Double

decimal 16 Decimal

char 2 Char

bool 1 Boolean
Non-primitive Data types

- String
- Array
- Class
Variables and …

- Scopes
- Type Conversion:
- Implicit Conversion
- Explicit Conversion (Type Casting)
- Conversion between non-compatible types
Demo: Greeter Program
Operators

- Arithmetic Operators: +, -, *, /, % , ++, --


- Assignment Operators: =, +=, -=, *=, …
- Comparison Operators: ==, !=, >,<,>=,,<=
- Logical Operators: &&, ||, !
Strings

- String Length
- Concatenation
- Special Characters
- Accessing string characters
If… else

if (condition)
{
// block of code to be executed if the condition is True
}
else
{
// block of code to be executed if the condition is False
}
Ternary Operator

variable = (condition) ? expressionTrue : expressionFalse;


While Loop

while (condition) do

{ {

// code block to be executed // code block to be executed

} }
while (condition);
For Loop

for (statement1; statement2; statement3)


{
// code block to be executed
}
Foreach

foreach (type variableName in arrayName)


{
// code block to be executed
}
Arrays

- Creating arrays -> type[] identifier= {value1 [,value2, value3]}


- Accessing Elements of an Array
- Array Length
Methods

- Method Parameters
- Default/ Optional Parameters
- Static Methods
- Return Values
- Method Overloading

You might also like