MSDN Documentation

Value Types

Value types are data types that hold their data directly. They are stored in the stack (or inline in a containing type) and are copied on assignment.

In C#, the following are considered value types:

Why use value types?

Common Value Types

TypeAliasSizeRange
System.Booleanbool1 bitTrue/False
System.Bytebyte8 bits0 to 255
System.SBytesbyte8 bits-128 to 127
System.Int16short16 bits-32,768 to 32,767
System.UInt16ushort16 bits0 to 65,535
System.Int32int32 bits-2,147,483,648 to 2,147,483,647
System.UInt32uint32 bits0 to 4,294,967,295
System.Int64long64 bits-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
System.UInt64ulong64 bits0 to 18,446,744,073,709,551,615
System.Singlefloat32 bits±1.5 × 10⁻⁴⁵ to ±3.4 × 10³⁸
System.Doubledouble64 bits±5.0 × 10⁻³²⁴ to ±1.7 × 10³⁰⁸
System.Decimaldecimal128 bits±1.0 × 10⁻²⁸ to ±7.9 × 10²⁸
System.Charchar16 bitsUnicode character

Struct Example

Below is a simple struct representing a 2‑D point:

public struct Point
{
    public double X { get; }
    public double Y { get; }

    public Point(double x, double y)
    {
        X = x;
        Y = y;
    }

    public double Length() => Math.Sqrt(X * X + Y * Y);
}
Try it in the playground

Related Topics