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

User Defined Data Types (UDDT) Can Be Used To Create A Composite Data Type That Can

User defined data types (UDDTs) can be used to create composite data types that store groups of primitive data types, which is useful for object-oriented programming where each object represents a real-life entity. Structures are value types that use stack memory allocation and cannot inherit from other types, while classes are reference types that use heap memory and can inherit from other structures or classes. Structures are immutable while classes are mutable. Structures are suitable for lightweight objects like Points while classes are suitable for representing heavyweight entities like Products.

Uploaded by

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

User Defined Data Types (UDDT) Can Be Used To Create A Composite Data Type That Can

User defined data types (UDDTs) can be used to create composite data types that store groups of primitive data types, which is useful for object-oriented programming where each object represents a real-life entity. Structures are value types that use stack memory allocation and cannot inherit from other types, while classes are reference types that use heap memory and can inherit from other structures or classes. Structures are immutable while classes are mutable. Structures are suitable for lightweight objects like Points while classes are suitable for representing heavyweight entities like Products.

Uploaded by

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

Overview

Limitation with primitive data types is that they can store only one type of value such as
bool/int/char/etc.,

User Defined Data Types (UDDT) can be used to create a composite data type that can
store group of primitive data types. This is especially useful when writing Object
Oriented Programming where each Object represents a real life entity.

Specific to .Net all the predefined functionality in Base Class Library (BCL) are Objects.
And all Objects are derived from System.Object.
UDDT can be Value Type (Structure) or Reference Type (Class).
Structure vs Class
Structure (struct) Class (class)
Differences
A struct type is a value type. A class type is a reference type.

Uses Stack memory allocation. Uses Heap memory allocation.

Members can not be declared as protected. Members can be declared as protected.

Structures cannot inherit other structures Classes can inherit other structures or
or classes. classes.

Structures do not require constructors. Classes require constructors.

Structures cannot have default Classes can have default constructors.


constructors.
Garbage Collector do not reclaim Structures Garbage Collector reclaim Objects created
from memory. from memory.
Structure vs Class

Structure (struct) Class (class)


Differences
A struct is IMMUTABLE. A class is MUTABLE.

DEMO
Structure vs Class

Structure (struct) Class (class)


Differences
A struct is IMMUTABLE. A class is MUTABLE.

DEMO
Structure vs Class

Structure (struct) Class (class)


Differences
A struct is IMMUTABLE. A class is MUTABLE.

DEMO
Structure vs Class
Structure (struct) Class (class)
Differences
You can create a struct object You can create a class object only by
with/without using the new operator. using the new operator.

DEMO

Note: If the struct has private fields, you must use the ‘new’ operator.
Structure vs Class
Structure (struct) Class (class)
Similarities
A struct and class can contain constructors, constants, fields, methods, properties,
indexers, operators, events, and nested types. And can implement interface.

DEMO
Structure vs Class
Structure (struct) Class (class)
Similarities
Both of them can have constructors with parameter.
Both can have delegates and events.
Structure vs Class

Structure (struct) Class (class)


Usage

The struct type is suitable for The class type is suitable for
representing light-weight objects such representing heavy-weight objects that
as Point, Rectangle, and Color. reflect the real-world entities such as
Human, Product, Car, etc.
Although it is possible to represent a Although it is possible to represent a
coordinate using a class, a struct is real world person using a struct, a class
more efficient in some scenarios. For is more efficient and extendable. For
example, if you declare an array of example, if you want to generalize the
1000 Point objects, you will allocate person entity with Employee class, it is
additional memory for referencing possible only by using class.
each object. In this case, the struct is
less expensive.

You might also like