Monty
Monty

Reputation: 133

c# - is SHORT data type or it is still INT?

I am doing some classification and I am not sure:

INT is a primitive datatype with keyword "int"

But I can use Int16,Int32 or Int64 - I know C# has its own names for them. But are those data types as well or it is still INT? And mainly, can we say "short" is a datatype or INT16 is a datatype? Thanks :)

Upvotes: 10

Views: 29702

Answers (3)

David
David

Reputation: 73594

In C#, int is just a shorter way of saying System.Int32.

In .NET, even the primitive data types are actually objects (derived from System.Object).

So an int in C# = an Integer in VB.Net = System.Int32.

there's a chart of all the .NET data types here: http://msdn.microsoft.com/en-us/library/47zceaw7%28VS.71%29.aspx

This is part of the .NET Common Type System that allows seamless interoperability between .NET languages.

Upvotes: 2

BoltClock
BoltClock

Reputation: 724452

short is a data type representing 16-bit integers (1 order below int, which is 32-bit).

Int16 is in fact also a data type and is synonymous with short. That is,

Int16.Parse(someNumber);

also returns a short, same as:

short.Parse(someNumber)

Same goes with Int32 for int and Int64 for long.

Upvotes: 3

Mike Caron
Mike Caron

Reputation: 14561

In C#, the following things are always true:

  • short == Int16
  • ushort == UInt16
  • int == Int32
  • uint == UInt32
  • long == Int64
  • ulong == UInt64

Both versions are data types. All of the above are integers of various lengths and signed-ness.

The main difference between the two versions (as far as I know) is what colour they are highlighted as in Visual Studio.

Upvotes: 28

Related Questions