Skip to main content
nint is a native-sized signed integer type in C# that adapts its memory footprint to match the underlying architecture of the execution environment. It occupies 32 bits (4 bytes) in a 32-bit process and 64 bits (8 bytes) in a 64-bit process. Introduced in C# 9.0, nint (along with its unsigned counterpart, nuint) integrates native-sized integers directly into the C# type system as first-class numeric types.

CLR Representation

At compile time, the C# compiler translates nint to the System.IntPtr struct. In Intermediate Language (IL), there is no distinction between nint and IntPtr. However, at the language level, the C# compiler applies different semantic rules to nint, treating it as a numeric primitive rather than an opaque pointer type.

Memory Layout and Bounds

Because the size of nint is evaluated at runtime by the CLR, its minimum and maximum values depend on the host architecture:
  • 32-bit architecture: Equivalent to System.Int32 (-2,147,483,648 to 2,147,483,647).
  • 64-bit architecture: Equivalent to System.Int64 (-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807).
You can access these bounds programmatically using the type’s static properties:

Type System and Operations

Unlike IntPtr in older versions of C#, nint natively supports standard arithmetic, comparison, and bitwise operators without requiring the unsafe context or manual casting.

Conversions

The C# compiler enforces strict conversion rules for nint to prevent overflow exceptions across different architectures. Implicit Conversions: Types that are guaranteed to fit within a 32-bit integer can be implicitly converted to nint.
  • sbyte, byte, short, ushort, int
Explicit Conversions: Types that exceed 32 bits, or types that nint might exceed on a 64-bit system, require explicit casting.
  • To nint: uint, long, ulong, nuint, float, double, decimal
  • From nint: sbyte, byte, short, ushort, int, uint, long, ulong, nuint

Compile-Time Constants

You can declare nint as a const, but the assigned value must be resolvable at compile time and must fit within the bounds of a 32-bit signed integer (Int32). The compiler enforces this restriction because it cannot guarantee that a 64-bit value will be valid on the target machine at runtime.
Tired of Poor C# Skills? Fix That With Deep Grasping!Learn More