Petr
Petr

Reputation: 569

C#: Is data type the same as type?

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?

Upvotes: 3

Views: 433

Answers (6)

Conrad Frix
Conrad Frix

Reputation: 52645

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.

Upvotes: 0

Adam Robinson
Adam Robinson

Reputation: 185593

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.

Upvotes: 2

shahkalpesh
shahkalpesh

Reputation: 33476

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).

Upvotes: 0

Bablo
Bablo

Reputation: 916

Same thing, just think of it as Type. To be specific, A in your example is a reference type.

Upvotes: 0

Darin Dimitrov
Darin Dimitrov

Reputation: 1038720

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.

Upvotes: 7

Jason Kleban
Jason Kleban

Reputation: 20758

Same thing

Upvotes: 4

Related Questions