Grade 10 W2 - Q2
Grade 10 W2 - Q2
Grade 10 W2 - Q2
5
Boolean
6
char 7
int 8
Boolean
9
str 10
double 11
float 12
double
RESET
LEARNING TARGETS
1. Differentiate variables, constraints, and
literals.
2. Use variables, constraints, and literals in
creating programs.
3. Identify and assign the correct data type to a
variable.
4. Construct statements and code blocks using
Visual C#.
What is a variable?
A VARIABLE is a programmer-
defined word that holds the value of
the user. It also saves a portion of
the memory to store a determined
value.
Since variables are programmer-
defined words there are rules to
follow in declaring them in a
program.
Rules in declaring
variable
1. It must begin with a letter or an underscore (_),
followed by letters, digits, or underscores.
2. It must not include blanks.
3. It must not be the keywords which are reserved
words by the language.
4. It must not be given a name with the same name as
other functions.
5. Variables in C# are case sensitive. For example,
variable DepEd is different from deped.
What is a constant?
A CONSTANT is an expression
with a fixed value that cannot be
changed at runtime, unlike a
variable whose value can be
changed during runtime based on
the user’s input.
To declare a constant in C#, the const
keyword is used.
This syntax should be followed:
const <data_type> <constant_name> = value;
Example:
const short a=10;
In the const short a=10; declaration,
a is declared as a constant with a
fixed value of 10.
Example:
string name;
int a, b, c;
A variable can have an initial value by adding a
value to it during declaration. It is declared as:
<Data type><variable name> = value;
Example:
int A=5;
double B=2.9;
double pi=3.1416;
Data types in C# can be categorized as
value types, reference types and pointer
type.