Existance pointers in c#
-
hi, does in c# exist a type of variable that is like pointers in c++? I mean, in c++, if I use a pointer to a byte, I can add 1 to this pointer and, in this way, move it along all the array, in c#, is there a way to do a similar thing? Thank you.
-
hi, does in c# exist a type of variable that is like pointers in c++? I mean, in c++, if I use a pointer to a byte, I can add 1 to this pointer and, in this way, move it along all the array, in c#, is there a way to do a similar thing? Thank you.
Yes. They are called "pointers": Pointer types - C# Programming Guide | Microsoft Docs[^] Do note that you need to specify
unsafe
for yoru code in order to use them, and you need to take precautions that the memory won't be moved by the GC while you are using the pointers. If you don't need 'em, don't use 'em: and that's "real need" not "I need this to be like my C++ code"."I have no idea what I did, but I'm taking full credit for it." - ThisOldTony AntiTwitter: @DalekDave is now a follower!
-
hi, does in c# exist a type of variable that is like pointers in c++? I mean, in c++, if I use a pointer to a byte, I can add 1 to this pointer and, in this way, move it along all the array, in c#, is there a way to do a similar thing? Thank you.
There's no need to do things like that in c#, so if you find yourself doing things like that then you probably need to rethink your solution and find one more suitable to the language.
-
hi, does in c# exist a type of variable that is like pointers in c++? I mean, in c++, if I use a pointer to a byte, I can add 1 to this pointer and, in this way, move it along all the array, in c#, is there a way to do a similar thing? Thank you.
-
hi, does in c# exist a type of variable that is like pointers in c++? I mean, in c++, if I use a pointer to a byte, I can add 1 to this pointer and, in this way, move it along all the array, in c#, is there a way to do a similar thing? Thank you.
If you're using a relatively recent version of the compiler, you might want to look at the
Span<T>
type: Span – Adam Sitnik – .NET Performance and Reliability[^] C# 7.2: Understanding Span | Connect(); 2017 | Channel 9[^] You'll probably need to add a reference to theSystem.Memory
NuGet package[^] to use it.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
hi, does in c# exist a type of variable that is like pointers in c++? I mean, in c++, if I use a pointer to a byte, I can add 1 to this pointer and, in this way, move it along all the array, in c#, is there a way to do a similar thing? Thank you.
Yes. Pointers do exist in C# Refer this link for pointers in C#: Pointers in C#