29
Variables and Data types [email protected] Programming in C#

2 variables and data types

Embed Size (px)

Citation preview

Page 1: 2   variables and data types

Variables and Data types

[email protected]

Programming in C#

Page 2: 2   variables and data types

Using variables

Memory is allocated to a variable at the time of its creation.

Syntax:

<datatype> <variableName>;

int empNumber;

empNumber = 100;

string empName = “M. Nolan”;

Page 3: 2   variables and data types

Data Types

Value Types

store actual values.

the values are stored in stack.

int, float, double, …

Reference Types

store the memory address

of other variables

in heap

string, class

Page 4: 2   variables and data types
Page 5: 2   variables and data types

Classification

Object

String

Class

Delegate

Interface

Array

Page 6: 2   variables and data types

Rules

Recommended CAMELCASE

int totMonths = 12

Page 7: 2   variables and data types

Question?

Page 8: 2   variables and data types

Question?

Page 9: 2   variables and data types

Comments and XML Documentation

Page 10: 2   variables and data types

Definition

Single-line Comments

Multi-line Comments

XML Comments

Page 11: 2   variables and data types

XML Documentation

Page 12: 2   variables and data types

Predefined XML Tags

Page 13: 2   variables and data types

Constants and Literals

Page 14: 2   variables and data types

Constants

possible to declare constants for all data types.

have to initialize a constant at the time of its declaration.

The compiler identify constants at the time of compilation

Page 15: 2   variables and data types

Using Literals

A literal is a static value assigned to variables and constants.

Numeric literals might suffix with a letter of the alphabet to indicate the data type of the literal.

Boolean => bool

Integer => int, uint (u), long (l), ulong (ul or lu)

long val = 53L;

Real => float(f), double(d), decimal(m)

float val = 1.66f;

Character

String => regular or verbatim.

Null

Page 16: 2   variables and data types

Keywords and Escape Sequences

Page 17: 2   variables and data types

Keywords

Page 18: 2   variables and data types

Escape Sequence Characters

Page 19: 2   variables and data types

Input and Output

Page 20: 2   variables and data types

Console Operations

are tasks performed on the command line interface.

All console application consist of three streams

Standard in

Standard out

Standard err

Page 21: 2   variables and data types

Output Methods

Console.Write()

Console.WriteLine()

Page 22: 2   variables and data types

Placeholders

Page 23: 2   variables and data types

Input Methods

Console.Read()

Console.ReadLine()

Page 24: 2   variables and data types

Convert Methods

Page 25: 2   variables and data types

Numeric Format Specifiers

Console.WriteLine(“{format specifier}, <variable name>”);

Page 26: 2   variables and data types

Numeric Format Specifiers

Page 27: 2   variables and data types

Standard Date and Time Format Specifiers

Page 28: 2   variables and data types

Standard Date and Time Format Specifiers

Page 29: 2   variables and data types

Question

What is result of following code snippet?