C# Basic - Datatype
C# Basic - Datatype
1
Data Types
3
1. Value data type
4
2. Reference Data Type
5
Built-in Data Types in C#
6
Why String type immutable:
● Strings are immutable, which means we are creating new memory every time instead of
working on existing memory. [System.String]
● Using same memory location & keep an appending/modifying the stuff to one instance [eg
String Builder]
● Why string immutable - for thread safety.
Questions:
1. Immutable vs Mutable?
2. Why string is immutable?
7
Static & non-static members
8
Static & non-static members eg
9
Static & non-static methods:
10
Rules while working with static & non-static:
11
Static Class in C#
12
Stack vs Heap
Stack :
1. It is an array of memory.
2. It is LIFO data structure.
3. Value of variable storing in stack.
4. Value type - int, long,double, bool etc
5. Static memory allocations
6. Memory deallocate when scope ends.
13
Stack vs Heap
Heap:
14
Heap Eg.
15
Data type conversion
Int a =10;
Float b = a; //10.0
16
Data type conversion
Float a =10.5;
Int b = (int)a;
17
Methods
Method Body
18
Methods
1. Access Specifier − This determines the visibility of a variable or a method from another class.
2. Return type − A method may return a value. The return type is the data type of the value the
method returns. If the method is not returning any values, then the return type is void.
3. Method name − Method name is a unique identifier and it is case sensitive. It cannot be same as
any other identifier declared in the class.
4. Parameter list − Enclosed between parentheses, the parameters are used to pass and receive data
from a method. The parameter list refers to the type, order, and number of the parameters of a
method. Parameters are optional; that is, a method may contain no parameters.
5. Method body − This contains the set of instructions needed to complete the required activity.
19
Thank You
www.codemindtechnology.com
20