Language: EN


What are group types

Groupings of elements are data structures that allow combining and organizing variables related to each other into a single variable.

We define these groupings ourselves and they can contain different types of variables, such as numbers, text strings. They can even contain other groupings.

For example, imagine that you have to save a person’s data. This data is, for example:

  • Name
  • Date of birth
  • Email

For example, we could use independent variables to store the person’s data

string name;
DateTime dateOfBirth;
string email;

But, imagine that we have to work with more than one person… What are we going to do? Use name1, name2…?

// This would not be practical at all!
string name1;
string name2;
string name3;

DateTime dateOfBirth1;
DateTime dateOfBirth2;
DateTime dateOfBirth3;
// etc...

It wouldn’t be very practical, or comfortable to use. It would also be a possible source of errors, as we could easily mix them up by mistake.

Instead, it is much better to create a grouping of variables. For example,

    string name;
    DateTime dateOfBirth;
    string email;

Now, we can create a new Person, and access its properties using the . operator.

Person person1; = "Juan Pérez";
person1.dateOfBirth = new DateTime(1990, 5, 15); = "";


If we had to work with more than one person, we would simply have to create person2, person3

Person person1;
Person person2;
Person person3;

This has the advantage that the data for each person is grouped in a “pack”. In addition to being more convenient to use, it is much more difficult to accidentally mix data from one another.

Common types of groupings

There are several types of groupings used in programming, each with its own characteristics and uses. The most common ones are: