Chapter 2
Variables - Constants –
Expressions
Flow control - Methods
What you will learn in this
chapter
Basic C# syntax: variables, constants,
expressions
How to branch code, loop code
How to write and call method
How to catch an exception
2
Contents
1. Variables - Constants - Expressions
2. More about variables
3. Flow control
4. Methods
5. Using some classes
6. Exception
Ebook: from chapter 1 to 6 (Part I)
3
Variables, Constants
Declare variable:
example: int x, y;
note: Variables need to be initialized before it’s
used
Declare constant:
example: const double PI = 3.14;
Data types that are built into C#
DataType name;
DataType name = init_value;
const DataType CONST_NAME =
value;
4
Primitive Data Types
5