2

Introducing C# 11: Numeric IntPtr and UIntPtr

 1 year ago
source link: https://anthonygiretti.com/2022/12/04/introducing-c-11-numeric-intptr-and-uintptr/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Introducing C# 11: Numeric IntPtr and UIntPtr

2022-12-04 by anthonygiretti

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! 🙂

Like this:


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK