Geeks With Blogs

News
Neat Stuff Read all my hurricane entries While you are here, visit the Geeks With Blogs main feed
Advertising
Links Status of the Navy
Channel 9

.NET Hobbyist Programmer Staying Confused in a Busy World

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.

Posted on Sunday, March 25, 2012 8:34 PM Programming , Software | Back to top


Comments on this post: C# Value Type Table

# re: C# Value Type Table
Requesting Gravatar...
Thanks. I remember looking for something like this as well.
Left by David on Mar 26, 2012 3:16 PM

# re: C# Value Type Table
Requesting 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
Left by Oscar on Sep 23, 2012 5:41 PM

Your comment:
 (will show your gravatar)


Copyright © Mark Treadwell | Powered by: GeeksWithBlogs.net | Join free