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.

This article is part of the GWB Archives. Original Author: Mark Treadwell

New on Geeks with Blogs

  • We Won The One Award I Actually Care About

    Full Scale made the Inc. 5000 for the fifth year straight, the 12th listing across my three companies. Here is why the one award you cannot buy is worth stopping for.

  • Your Customers Build the Features Now

    I let a tool I liked sit dead for a year rather than build the features I wanted. An MCP server meant I never had to, and your customers can do the same to your product.

  • Get the Size of a Directory in Linux the Easy Way

    du -sh for the quick answer, ncdu for the cleanup, df for the disk itself: every command for checking directory size in Linux, plus why du and df never agree.

  • Vim Search and Replace: The Ultimate Guide

    One :%s command replaces every match in a file before a find dialog would even open. The Vim substitute patterns worth the muscle memory: flags, ranges, capture groups, and multi-file edits.