SHARE:

Introducing C# 11: Numeric IntPtr and UIntPtr

Introduction

Before explaining to you what’s new in C# 11 on the IntPtr and UInPtr types, I’ll refresh your memory of what these types are. Two years ago I wrote a post about these types, named “Native-sized Integers”, so I invite you to read it again here: https://anthonygiretti.com/2020/08/19/introducing-c- 9-native-sized-integers/.

Now that your memory is refreshed, I will be able to explain to you what is new in C# 11.

The novelty in C# 11 with Native-sized Integers

Since C# 9 the types nint and nuint are considered respectively as types System.IntPtr and System.UIntPtr since they are similar. Here is the specification from C# 9 (source: Microsoft):
“The types nint and nuint are represented by the underlying types System.IntPtr and System.UIntPtr with compiler surfacing additional conversions and operations for those types as native ints.”
If you want to read the full specification you can find it here: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-9.0/native-integers.

However since C# 11, Microsoft no longer considers them similar but identical to the point of making nint and nunit aliases of System.IntPtr and System.UIntPtr. No more no less! 🙂

Written by

anthonygiretti

Anthony is a specialist in Web technologies (14 years of experience), in particular Microsoft .NET and learns the Cloud Azure platform. He has received twice the Microsoft MVP award and he is also certified Microsoft MCSD and Azure Fundamentals.