Hi, maybe its silly but I am not sure if there is difference between types and data types
int
is data type
class A{}
A is type or data type?
Hi, maybe its silly but I am not sure if there is difference between types and data types
int
is data type
class A{}
A is type or data type?
Actually in .NET there are reference types and value types. Value types are enum
or struct
and reference types are class
.
int
is an alias to System.Int32 which is a struct and so value type, while in your case A
is class, so reference type.
Same thing, just think of it as Type. To be specific, A in your example is a reference type.
A
is a type that can have properties/member variables which can be of other types or data types (int
,string
)
But then, in terms of framework everything is a type (reference or value).
There is no such thing as a "data type" in any .NET language. "Data type" is often used to clarify "type" to refer to the actual runtime type of the variable rather than a more abstract notion of what "kind" of value is present.
int
is what's referred to as a value type. All primitive types (int
, double
, char
, etc.) are value types, with the exception of string
, which is a reference type (though, like value types, it's immutable).
Any object declared as a class
is a reference type. Any object declared as a struct
is a value type.
From the C# Spec Section 1.3
1.3 Types and variables
There are two kinds of types in C#: value types and reference types. Variables of value types directly contain their data whereas variables of reference types store references to their data, the latter being known as objects. With reference types, it is possible for two variables to reference the same object and thus possible for operations on one variable to affect the object referenced by the other variable. With value types, the variables each have their own copy of the data, and it is not possible for operations on one to affect the other (except in the case of ref and out parameter variables).
C#’s value types are further divided into simple types, enum types, struct types, and nullable types, and C#’s reference types are further divided into class types, interface types, array types, and delegate types.
and int is a value type that is also a simple type and is also a Signed integral
class a{} is a reference type that is a class type that is user defined.