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.
nuint is a native-sized unsigned integer type introduced in C# 9.0. Its memory footprint and value range are platform-dependent, resolving to 32 bits (4 bytes) in a 32-bit execution context and 64 bits (8 bytes) in a 64-bit execution context. It serves as the C# equivalent of the C/C++ size_t type, making it a critical primitive for P/Invoke, unmanaged interoperability, and representing memory sizes or indices.
Type System Mapping
At the compiler level, thenuint keyword is an alias for the .NET System.UIntPtr struct. However, unlike the legacy UIntPtr type in older versions of C#, nuint is treated by the compiler as a primitive numeric type. This enables direct support for arithmetic, bitwise, and comparison operations without requiring manual method calls.
Value Range
Because the size is determined at runtime by the host architecture, the maximum value ofnuint fluctuates:
- 32-bit process:
0to4,294,967,295() - 64-bit process:
0to18,446,744,073,709,551,615()
nuint.MinValue and nuint.MaxValue. Because the size of nuint depends on the runtime architecture, these boundaries are implemented as static readonly fields (in C# 9) or static properties (in .NET 7+). They are not compile-time constants (const). Consequently, they cannot be used in constant expressions, such as default parameter values, attribute arguments, or switch cases.
Syntax and Operations
nuint supports standard mathematical and bitwise operators (+, -, *, /, %, ~, &, |, ^, <<, >>).
Type Conversions
The compiler enforces strict conversion rules based on the guarantee thatnuint is at least 32 bits wide and at most 64 bits wide.
Implicit Conversions:
Unsigned types that are 32 bits or smaller can be implicitly converted to nuint because they are guaranteed to fit within the type’s memory space regardless of the architecture. Conversely, nuint can be implicitly converted to ulong. Because nuint maxes out at 64 bits, it is guaranteed to fit inside a 64-bit ulong without data loss.
ulong to nuint, or converting any signed type to nuint, requires an explicit cast. A 64-bit integer might overflow a 32-bit nuint at runtime, and signed integers violate the unsigned constraint.
Pointer Interoperability
nuint is deeply integrated with C#‘s unsafe pointer types. It can be explicitly cast to and from any unmanaged pointer type, representing the exact memory address. As the equivalent of size_t, it is the standard type for passing pointer sizes, buffer lengths, and memory block indices to native APIs via P/Invoke.
Reflection and Overloading
Becausenuint is a language-level projection of System.UIntPtr, they are indistinguishable via reflection at runtime. Consequently, method overloading cannot differentiate between nuint and UIntPtr.
Master C# with Deep Grasping Methodology!Learn More





