On day 1 on the C# development, we should be aware about the basic variables used in C#.
Variables are like the store unit needed for the data storage while executing any program.
In C# variables are declared as below:
E.g. int a; string str;
The data types used to create a variables are of two types,
- Values Types:
The data types which are used to store the data which is allocated to the itself is called value types. The variable initialized as a value data type contains the value in it. The value types are stored in the stack memory.
E.g. Byte, int, float, char, double, decimal, bool etc.
- Reference Types:
The data types which holds the address/reference of the data are called reference types. The reference types are stored in the heap memory.
E.g. string, object.
Boxing & Unboxing:
Conversion of value of value type into value of reference type.
In boxing conversion permits any value type to be converted to the object type.
E.g. int a=1;
object b=a; //boxing
Conversion of value of reference type into value of value type.
In unboxing we perform explicit conversion of object type into value type.
E.g. object b=12;
int a=( int )b; //unboxing
Operators in C# are as below.
These include the operators used for mathematical purpose, like addition, subtraction, multiplication, division, modulus, increment & decrement operators.
- Addition (+)
- Subtraction (-)
- Multiplication (*)
- Division (/)
- Modulus (%)
- Increment (++)
- Decrement (–)
These include the operators which are used to perform logical operations like AND, OR & NOT.
- AND (&&)
- OR (||)
- NOT (!)
These includes the operators which are used for comparison purpose, like EQUAL TO, GREATER THAN & SMALLER THAN.
- EQUAL TO (==)
- NOT EQUAL TO (! ==)
- GREATER THAN (>)
- SMALLER THAN (<)
- GREATER THAN OR EQUAL TO (>=)
- SMALLER THAN OR EQUAL TO (<=)