1. Data Types in C#Data Types in C#
Made By;
Malik Zeeshan Ahmed
2.
3. C# Data TypesC# Data Types
Value types
Pre-defined:
◦ int, uint, float, etc.
User-defined:
◦ Structures and Enumerations
Reference types
Pre-defined:
◦ Objects
◦ Strings
User-defined:
◦ Classes
◦ Arrays
◦ Delegates
◦ Interfaces
Everything inherits from System.Object
4. C# Value vs. Reference
• Value Types “directly contain”
the variable data.
– Example: int, float, enum,
struct...
• Reference Types contain a
reference to the data
Memory
int x
int y
myObject
Reference Type
Memory
ref0
ref1
Value TypeReference Type
Memory
ref0
ref1
myObject
Memory
ref0
ref1
Reference Type
myObject
Memory
ref0
ref1
Reference Type
myObject
Memory
ref0
ref1
Reference Type
Memory
ref0
ref1
myObject
Reference Type
Memory
ref0
ref1
5. class ValueType
• ValueType is a class that inherits directly from object
– You cannot inherit from ValueType
• ValueType overrides System.Object methods so they make
sense
6. Value typeValue type
value-types inherit directly from ValueType
◦ Built in types(bool,int,…etc)
◦ enum types
◦ struct types
All value-types are sealed
value-types cannot be null
Assignment of a value-type results in a copy of the variable