Variable_Keyword_DataType_Array
Variable_Keyword_DataType_Array
ray
Variable
A variable is used to store data in a program and is declared with an associated data type.
A variable has a name and may contain a value.
A data type defines the type of data that can be stored in a variable.
A variable is an entity whose value can keep changing during the course of a program.
o Example: The age of a student, the address of a faculty member, and the salary of an
employee are all examples of entities that can be represented by variables.
In C#, a variable is a location in the computer’s memory that is identified by a unique name
and is used to store a value. The name of the variable is used to access and read the value
stored in it.
A variable is an entity whose value can keep changing during the course of a program.
Example: The age of a student, the address of a faculty member, and the salary of an
employee are all examples of entities that can be represented by variables.
In C#, a variable is a location in the computer’s memory that is identified by a unique name
and is used to store a value. The name of the variable is used to access and read the value
stored in it.
Kiểu tham trị (value type) và kiểu tham chiếu (reference type)
Null pointer
Reference types have null value by default, when they are not initialized.
For example, a string variable (or any other variable of reference type datatype) without a
value assigned to it.
In this case, it has a null value, meaning it doesn't point to any other memory location,
because it has no value yet.
A value type variable cannot be null because it holds a value not a memory address
Nếu ta có câu hỏi rằng nhiều reference type thì đầy heap, thì C# có garbage collector sẽ tự động xóa
chúng đi sau một khoảng thời gian.
When the common language runtime (CLR) boxes a value type, it wraps the value inside a
System.Object instance and stores it on the managed heap.
Boxing is implicit (ngầm định); unboxing is explicit (tường minh) phải chỉ rõ data type.
The concept of boxing and unboxing underlies the C# unified view of the type system in which a
value of any type can be treated as an object.
Unboxing is an explicit conversion from the type object to a value type or from an interface type to a
value type that implements the interface.
Checking the object instance to make sure that it is a boxed value of the given value type.
Copying the value from the instance into the value-type variable.
So sánh kiểu object, var, dynamic
CONSTANT
A constant has a fixed value that remains unchanged throughout the program while a literal provides
a mean of expressing specific values in a program.
These elements are accessed using subscripts or index numbers that determine the position of the
element in the array list.
This means that the first array element has an index number zero while the last element has
an index number n-1, where n stands for the total number of elements in the array.
This arrangement of storing values helps in efficient storage of data, easy sorting of data, and easy
tracking of the data length.
Arrays are reference type variables whose creation involves two steps:
Declaration:
An array declaration specifies the type of data that it can hold and an identifier.
This identifier is basically an array name and is used with a subscript to retrieve or set the
data value at that location.
Memory allocation:
Rectangular array
A rectangular array is a n-dimensional array where size of each dimension are equal.
It usually used to represent matrix. It’s very important to help to resolve math problems.
Example:
Linear Transformations
Matrix-Vector Multiplication Algorithms
Gaussian Elimination
LU Factorization
The Inverse Matrix
Jagged Array
Is a multi-dimensional array and is referred to as an array of arrays.
Consists of multiple arrays where the number of elements within each array can be
different. Thus, rows of jagged arrays can have different number of columns.
Optimizes the memory utilization and performance because navigating and accessing
elements in a jagged array is quicker as compared to other multi-dimensional arrays.