Blog Stats
  • Posts - 276
  • Articles - 2
  • Comments - 301
  • Trackbacks - 660

 

C# Value Type Table

One of the things I always seem to be checking are the various characteristics of the C# value types.  You know, stupid questions like whether int is the same as System.Int32 or System.Int64.  I know the answer, but when I need it, I just want a quick reference.  I could not find one, so I made one.  I think it is correct since I combined multiple tables from the MSDN documentation.

Value Type

Category

.NET Framework Type

Approximate Range

Default Value

Literal

Size

Precision

Implicit Numeric Conversions

Explicit Numeric Conversions

sbyte

Signed, numeric, integral

System.SByte

-128 to 127

0

1 byte

-

short, int, long, float, double, or decimal

byte, ushort, uint, ulong, or char

byte

Unsigned, numeric, integral

System.Byte

0 to 255

0

1 byte

-

short, ushort, int, uint, long, ulong, float, double, or decimal

Sbyte or char

char

Unsigned, numeric, integral

System.Char

\x0000 to \xFFFF (hex)

\u0000 to \uFFFF (uni)

(char)0 to (char)65535

'\0'

2 bytes

-

ushort, int, uint, long, ulong, float, double, or decimal

sbyte, byte, or short

short

Signed, numeric, integral

System.Int16

-32,768 to 32,767

0

2 bytes

-

int, long, float, double, or decimal

sbyte, byte, ushort, uint, ulong, or char

ushort

Unsigned, numeric, integral

System.UInt16

0 to 65,535

0

2 bytes

-

int, uint, long, ulong, float, double, or decimal

sbyte, byte, short, or char

int

Signed, numeric, integral

System.Int32

-2,147,483,648 to 2,147,483,647

0

4 bytes

-

long, float, double, or decimal

sbyte, byte, short, ushort, uint, ulong, or char

uint

Unsigned, numeric, integral

System.UInt32

0 to 4,294,967,295

0U

U u

4 bytes

-

long, ulong, float, double, or decimal

sbyte, byte, short, ushort, int, or char

long

Signed, numeric, integral

System.Int64

-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

0L

L

8 bytes

-

float, double, or decimal

sbyte, byte, short, ushort, int, uint, ulong, or char

ulong

Unsigned, numeric, integral

System.UInt64

0 to 18,446,744,073,709,551,615

0UL

UL, ul, Ul, uL, LU, lu, Lu, or lU

8 bytes

-

float, double, or decimal

sbyte, byte, short, ushort, int, uint, long, or char

float

Numeric, floating-point

System.Single

±1.5e-45 to ±3.4e38

0.0F

F f

4 bytes

7 digits

double

sbyte, byte, short, ushort, int, uint, long, ulong, char, or decimal

double

Numeric, floating-point

System.Double

±5.0e-324 to ±1.7e308

0.0D

D d

8 bytes

15-16 digits

long

sbyte, byte, short, ushort, int, uint, long, ulong, char, float, or decimal

decimal

Numeric, decimal

System.Decimal

±1.0 × 10^−28 to ±7.9 × 10^28

0.0M

M m

16 bytes

28-29 digits

-

sbyte, byte, short, ushort, int, uint, long, ulong, char, float, or double

 

There is also a PDF that I still need to upload.


Feedback

# re: C# Value Type Table

Gravatar Thanks. I remember looking for something like this as well. 3/26/2012 3:16 PM | David

# re: C# Value Type Table

Gravatar Cool, it is always good to look back and make sure we don't waste memory by choosing the wrong types, many times we use an int and the value never goes higher than what a short or a byte can hold.
Thanks 9/23/2012 5:41 PM | Oscar

Post A Comment
Title:
Name:
Email:
Comment:
Verification:
 
 

 

 

Copyright © Mark Treadwell