C# is an Object-oriented programming language. C# comes with simplicity, expressiveness and great performance to meet the programmer productivity.
So far, we have discussed the multidimensional arrays
in C#. Now let's see about variables and some memory elements of C# in this chapter.
The main objective of this article is to learn about variables, stack, heap, definite assignment and default values of C# programming
represents a storage location of the memory that contains a modifiable value (data which can be changeable).
It can be a
parameter (value, out or ref),
local variable (described locally),
field (static or instance), or an
Stack and HeapStack and Heap are the important parts of the memory where
variables reside in.
Note: We cannot delete the
objects in C# explicitly as we do in C++
C# enforces the definite assignment policy. This means, it is impossible to access the unallocated (or uninitialized) memory from the outside.
Definite assignment policy has three implications, which are,
- Local variables must have been assigned a value before they can be read.
- When a method is called, Function arguments must be supplied.
- Other elements such as array elements and fields are automatically initialized by the runtime.
, all the type instances have the default values which results as bitwise zeroing of the memory.
- For all reference types -
- For all numeric and enum types -
- For bool type -
- For char type - '
In order to obtain the default value for any type, we have to use the
In this article, we have seen what is variable and memory elements of C#. Hope you understood the article.
Thanks for reading.