C# Data Types Size

In the previous section, you have learned about the Data Types in C#. In this section, you will learn about the size of Data Types.

As we know that to create an application in C# we often create fields and properties to maintain the values across different operations. To declare a specific type of field and property we use Data Types. These Data Types have a size in memory, so they can store the values according to their sizes.

To create a better application we must use the Data Types wisely, as Data Types takes space in memory, so memory utilization is very important for an application. For example a byte Data Type can be used to store the age of a person, As a byte can store the value from 0-255, which is enough to store an age.

In C# there are numbers of Data Types which can be used to store different kinds of values. Following is the list of different Data Types and their sizes.

Value Types - Integral

Alias .NET Type Type Size (byte) Range (values)
byte Byte Unsigned integer 1 0 to 255
sbyte SByte Signed integer 1 -128 to 127
char Char A singe unicode character 2 U+0000 to U+ffff. Unicode symbols used in text.
int Int32 Signed integer 4 -2,147,483,648 to 2,147,483,647
uint UInt32 Unsigned integer 4 0 to 4294967295
short Int16 Signed integer 2 -32,768 to 32,767
ushort UInt16 Unsigned integer 2 0 to 65,535
long Int64 Signed integer 8 -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
ulong UInt64 Unsigned integer 8 0 to 18,446,744,073,709,551,615

Value Types - Floating point

Alias .NET Type Type Size (byte) Range (values)
float Single Single-precision floating point type 4 -3.402823e38 to 3.402823e38
double Double Double-precision floating point type 8 -1.79769313486232e308 to 1.79769313486232e308

Value Types - Decimal

Alias .NET Type Type Size (byte) Range (values)
decimal Decimal Precise fractional or integral type that can represent decimal numbers with 29 significant digits 16 (+ or -)1.0 x 10e-28 to 7.9 x 10e28

Boolean Type

Alias .NET Type Type Size (byte) Range (values)
bool Boolean Logical Boolean type 1 True or False

Reference Types

Alias .NET Type Type Size (byte) Range (values)
object Object Object class is the Base type of all other types
string String A sequence of characters

Let's learn about the C# operators in the next section.