C# 11 – Numeric IntPtr
Let’s list all the features that C# 11 brings to the table. Let’s discuss them all one by one, with their use cases, and see how they can come in handy. At the bottom of each article, you can find a link to all 14 new C# features!
C# 11 brings an alias to IntPtr and UIntPtr. Those methods are used for some unsafe shenanigans, that this article is too short to define, but they are Pointers to memory. Or can be used as one.
IntPtr pointer = IntPtr.Zero; UIntPtr uIntPtr = UIntPtr.Zero;
Those two can now be aliased by either
nint pointer = nint.Zero; unint uIntPtr = unint.Zero;
Those are alias and do not change how you use them, they can be now user exchangeable.
I do not know how I feel about this change. I think that
IntPtr was clear and concise in its naming where
nint is not. Also the
n the letter at the start should suggest a pointer but it is not clear at first glance. I would probably still use IntPtr in my code where I can.
Further reading at dotnet GitHub page.
Founded in 2016 in Warsaw, Poland. Prographers mission is to help the world put the sofware to work in new ways, through the delivery of custom tailored 3D and web applications to match the needs of the customers.
C# 11 – Everything you need to know
C# 11 – ref fields and ref scoped variable
C# 11 – Improved method group