2 - NPL - Variable, Data Types, Keywords, Array
2 - NPL - Variable, Data Types, Keywords, Array
NET Programming
Language
Variable, Data types, Keywords, Array
1. Variable
2. Keywords
3. Data types
4. Array
Variable
Stores the value in its memory space Stores the address of the value where it is
stored
Primitive data types and struct Class objects, string, array, delegates
decimal 128-bit floating point with 28-29 digits precision ±1.0 × 10e−28 to ±7.9 × 10e28
Stri
• String is a built-in reference type that signifies Unicode character string values.
ng
Cla
• A class is a user-defined structure that contains variables and methods.
ss
• A delegate is a user-defined reference type that stores the reference of one or more
Del
egat methods.
e
• An array is a user-defined data structure that contains values of the same data type,
Arr
ay
such as marks of students.
In C#, you can decide to declare and assign value or declare variable only
In C#, you can declare multiple variables have same data type at the time
Var
Object Dynamic
y2x5__w7h3 Legal
yearly_cost Legal
Keywords
30
Keywords
Keywords are reserved words that are separately compiled by the compiler
and convey a pre-defined meaning to the compiler and hence, cannot be
created or modified.
Example: int, double, string, break, var, …
Escape sequence characters in C# are characters preceded by a
backslash (\) and denote a special meaning to the compiler.
You cannot use keywords as variable names, method names, or class
names, unless you prefix the keywords with the ‘@’ character
virtual volatile
41
Important Points
Array
Memory allocation:
– Declaring an array does not allocate memory to the array.
Creating and initializing an array with the new keyword involves specifying the
size of an array.
The number of elements stored in an array depends upon the specified size.
The new keyword allocates memory to the array and values can then be assigned
to the array.
If the elements are not explicitly assigned, default values are stored in the array.
Array
Single- Multi-
dimensional dimensional
array array
Rectangular
Jagged array
array
60
Example
Consider a class of 50 students
where each student has opted for
a different number of subjects.
Here, you can create a jagged
array because the number of
subjects for each student varies.
The following figure displays the
representation of jagged arrays: