0% found this document useful (0 votes)
26 views

7.data Types in C#

C# has value types and reference types as data types. Value types include primitive types like int and float as well as user-defined structs and enums, which store data directly. Reference types include classes, arrays, strings and delegates, which contain references to data stored in memory. Everything inherits from the System.Object class. Value types are stored on the stack while reference types are stored on the heap and referenced by pointers.

Uploaded by

michaeltamn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

7.data Types in C#

C# has value types and reference types as data types. Value types include primitive types like int and float as well as user-defined structs and enums, which store data directly. Reference types include classes, arrays, strings and delegates, which contain references to data stored in memory. Everything inherits from the System.Object class. Value types are stored on the stack while reference types are stored on the heap and referenced by pointers.

Uploaded by

michaeltamn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 9

Data Types in C#

C# 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

C# Value vs. Reference

Value Types directly contain


the variable data.
Example: int, float, enum,
struct...

Reference Types contain a


reference to the data

Reference Type

Value Type

Memory

Memory

ref0

int x
int y

ref1

myObject

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

Value 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

value-type Hierarchy
value-type

struct-type

enum-type

simple-type

type-name

numeric-type

bool

integral-type

floating-point-type

type-name

decimal

Reference Types

Classes
object (System.Object)
string
user-defined classes

Interfaces
Arrays
Delegates
delegate (System.Delegate)

Reference-type Hierarchy
reference-type

class-type

type-name

interface-type

object

array-type

delegate-type

string

You might also like