User Defined Data Types (UDDT) Can Be Used To Create A Composite Data Type That Can
User Defined Data Types (UDDT) Can Be Used To Create A Composite Data Type That Can
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.
Structures cannot inherit other structures Classes can inherit other structures or
or classes. classes.
DEMO
Structure vs Class
DEMO
Structure vs Class
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
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.