Documentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
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 translatesnint 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 ofnint 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,648to2,147,483,647). - 64-bit architecture: Equivalent to
System.Int64(-9,223,372,036,854,775,808to9,223,372,036,854,775,807).
Type System and Operations
UnlikeIntPtr 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 fornint 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
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 declarenint 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.
Master C# with Deep Grasping Methodology!Learn More





