What is the difference between a class and a datatype?

前端 未结 10 1095
广开言路
广开言路 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:33

    a class is a data type if a user creates a class, it is known as user defined data-type.

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

    class is a object oriented programming concept, and datatype is generic to all programming paradigm. Class is a datatype but datatype are not class

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

    A class is a kind of data type. Other kinds of data types include pointer types and interfaces.

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

    A class is a type of a data type. It allows you to declare a variable along with its datatype. E.g.:

    class big  
    {  
        public int a;  
        .......  
        ......    
    }    
    

    Here, int is a data type and big is the class name.

    Hope you got little idea about it!

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

    C# is a strongly typed language; therefore every variable and object must have a declared type.

    A data type can be described as being either:

    A built-in data type, such as an int or char, or

    A user-defined data type, such as a class or interface.

    Data types can also be defined as being either:

    Value Types (C# Reference), which store values, or

    Reference Types (C# Reference), which store references to the actual data.

    ** Class is a user define data type. **

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

    Classes are Reference Types.

    A Data Type is a value type if it holds the data within its own memory allocation.

    Reference types are allocated on the heap, and memory management is handled by the garbage collector. Value types are allocated on the stack or inline and are deallocated when they go out of scope. In general, value types are cheaper to allocate and deallocate.

    Like for example

    class Person
    {
       string name;
    }
    

    In this the class Person is reference type and name is value type i.e data type.

    struct Person
    {
       string name;
    }
    

    In this the struct Person is value type and also name is value type i.e both are data type.

    A data type is a value type if it holds the data within its own memory allocation. A reference type contains a pointer to another memory location that holds the data.

    In reference to MSDN article on Classes and Structures and also MSDN article on Reference Type and Value Type

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