views:

127

answers:

6

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?

+4  A: 

Same thing

uosɐſ
+7  A: 

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.

Darin Dimitrov
That is an important difference to understand, but "data type" and "type" refer to the same concept.
uosɐſ
Reference types are nullable, and value type are not.
controlbreak
@controlbreak: C# 3.0 introduced nullable value types. See [here](http://msdn.microsoft.com/en-us/library/1t3y8s4s.aspx): "Nullable types represent value-type variables that can be assigned the value of null."
0xA3
And let's not forget that at least five geese are referred to as a "Gaggle".
uosɐſ
@0xA3: Technically, .NET 2.0 introduced the concept of generics, which added the `Nullable<T>` structure. Syntactic sugar in VB.NET and C# starting with VS 2005 allowed for assignment and comparison to "null" (though it does not actually assign a null value to the struct, and comparison to null just checks the `HasValue` property).
Adam Robinson
I love the "??" in c# :)string PerhapsThisIsNull = null;string myText = PerhapsThisIsNull ?? "Hey it's null!";
controlbreak
@Adam Robinson: Thanks for the additional info. I didn't want to repeat all the details about nullable types in my comment. Of course, the struct itself is technically not null, sorry if this caused any confusion.
0xA3
A: 

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

Bablo
A: 

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

shahkalpesh
+2  A: 

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.

Adam Robinson
A: 

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.

Conrad Frix