You are on page 1of 14

Programming C# 2.0, 3.0, 4.

Muhammed Ali Sakhi


Microsoft Certified Trainer

© PakDev.net
Agenda
Understanding Value Types
Creating and Using Variables
Formatting Console Output

© PakDev.net
Value Types
Directly contain their data
Each has its own copy of data
Operations on one cannot affect another

© PakDev.net
Naming Variables and Rules
Rules
Use letters, the Answer42 
underscore, and digits 42Answer

Recommendations
Avoid using all
different
Different


uppercase letters
Avoid starting with
an underscore
BADSTYLE 
Avoid using
_poorstyle
BestStyle


abbreviations
Use PascalCasing
naming in multiple-word
Msg
Message 

names
© PakDev.net
Declaring Local Variables
Usually declared by data type and
variable name:
int itemCount;

Possible to declare multiple variables\ in


one declaration:
int itemCount, employeeNumber;
--or--
int itemCount,
employeeNumber;

© PakDev.net
Compound Assignment
Adding a value to a variable is very common
itemCount = itemCount + 40;

There is a convenient shorthand


itemCount += 40;

This shorthand works for all arithmetic


operators
itemCount -= 24;

© PakDev.net
Increment and Decrement
Changing a value by one is very common
itemCount += 1;
itemCount -= 1;

There is a convenient shorthand


itemCount++;
itemCount--;

This shorthand exists in two forms


++itemCount;
--itemCount;

© PakDev.net
Common Value Types

© PakDev.net
Common Value Types

© PakDev.net
String Formatting Example

© PakDev.net
DateTime Formatting

© PakDev.net
Value Types and Formatting

Demo

© PakDev.net
Demonstration Steps
Create a new console application
Create short integer variables
Apply some operations on variables
Read user input into string variables
Apply formatting on currency and date values

© PakDev.net
Thank you
PakDev.net

© PakDev.net

You might also like