Can a class be a type of data?

Asked

Viewed 297 times

6

What I understand about data type is that they are formed by three properties, they are:

  1. Address set;
  2. Set of Operations;
  3. Space in Memory;

Assuming what is above I can understand that a class I create for example class Pessoa:

public class Pessoa
{
   private string Nome {get; set;}

   public Pessoa()
   {
      this.Nome = "";
   }
}

That this class Pessoa is a type of data like string, int, char or double? Or a class cannot be considered a data type?

  • I can’t talk about the 3 items mentioned, it doesn’t seem to be a correct definition, but if you give a reference to where this is used or more details, I can try to talk about this.

  • It’s more conceptual even, the 3 items cited was what I understood in college, I may be wrong about that too.

1 answer

7


Yes, a class is a data type. In C# there is a clear definition of this even in its specification. The class is one of the possible types, the others are, so far, the structures (struct), the delegates (delegate), that can be expressed with Amble, the enumerations (enum), the interfaces (interface), and tuples (although there may be dispute whether it is a pure way to create a type).

The word guy is used generically to classify all these forms of data structures from the simplest to the most complex. Each of these different forms of structures cited has its own characteristics, but they are all statements of how one object must be formed.

So Pessoa before it is a class, it is a type. It has languages that have no proper explicit syntax for each form and calls everything from type.

If you use the operator typeof in Pessoa will get a guy (Type), obvious, right? So it’s a guy.

  • Fast and fast as always hehe

  • What would be the structures? A struct in this case?

  • That’s right...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.