16 November

C# 11 – Numeric IntPtr

Programming

min. read

Reading Time: < 1 minute
C# 11
C# 11

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!

Numeric IntPtr

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 or unint

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.


Let's talk

SEND THE EMAIL

I agree that my data in this form will be sent to [email protected] and will be read by human beings. We will answer you as soon as possible. If you sent this form by mistake or want to remove your data, you can let us know by sending an email to [email protected]. We will never send you any spam or share your data with third parties.

I agree that my data in this form will be sent to [email protected] and will be read by human beings. We will answer you as soon as possible. If you sent this form by mistake or want to remove your data, you can let us know by sending an email to [email protected]. We will never send you any spam or share your data with third parties.