What is the difference between a class and a datatype?

前端 未结 10 1096
广开言路
广开言路 2021-02-13 15:30

I have heard the following statement:

We can say class is a datatype or a datatype is one type of class.

Can anyone explain to me wh

相关标签:
10条回答
  • 2021-02-13 15:51

    All (or almost) all programming languages have a notion of a datatype. A datatype can be things like: Integers, doubles, booleans etc.

    C# and other languages allow us to define our own "custom" datatypes. That's where classes come in. Custom datatypes in OO languages are called classes and when we define such classes it is the type definition or type.

    Take a look at this Wikipedia page for more information

    0 讨论(0)
  • 2021-02-13 15:52

    This article from the MSDN might be of some use in this regard. It tries to explain what Objects, Classes and Structs are in terms of C#.

    0 讨论(0)
  • 2021-02-13 15:54

    A class is just one of the data types available in C#:

    Data Types:

    • Class
    • Struct
    • Enum
    • Delegate
    • Interface

    NOTE: I may be missing a few in above list

    0 讨论(0)
  • 2021-02-13 15:59

    A class is a data type. A datatype is a concept, it's not a class. That is to say, you look at something and say to yourself "Hmm yes, that is so-and-so type of data", or "That is this datatype". Then you say "Specifically, the datatype is List<..>", and so on.

    0 讨论(0)
提交回复
热议问题