Composite Data type in C#

c#

Solution

A composite data type is something you can divide into multiple other types. A box that contains more boxes, if you will. If a box is empty, then it's an elementary data type. A box that contains another box is a composite type, because you can separate it into smaller types.

Say you have a type that represents a mob in a game. How can you divide that into smaller objects to better understand and represent it?

That mob contains information, such as its name, attacks, hit points and equipment.

Now, its name could be represented as a string, so it is an elementary type. The hit points are represented with a number, so it too is a simple type. Empty boxes, if you follow my above example.

But what about its equipment? It could be represented with a composite type. An array of strings, for the sake of this example. Each mob has a list of what it carries. It could carry "sword", "boots" or anything else. An array is a composite type because you can separate it into a bunch of objects (string[] = multiple string objects).

Now, for its attacks. We need more than just a string or number to represent one attack. We need a name, and the amount of damage it inflicts, but also the extra effect it can inflict. This would be a box that contains other boxes.

Lastly, you can think of a composite type (class, array, struct) as a tree:

int[]
    int
    int
    int
    int

person
    name
    address
        civic number
        street
        city
    birth date

Hope it helps you understand.

Problem

Please help me in trying to understand - What is a Composite Datatype in C# - Are Custom Data Types and Composite Types are same in C# I need to use it in a WCF service, hence I need to have a clearer understanding for it.

Original source