pointers help
i want to make a function that swaps two ints using pointers but i get an error with the declaration of the function
14 Replies
this is mi code:
What is the error?
Also for this purpose, I would recommend ref instead of pointers
it says
Unsafe code may only appear if compiling with /unsafe
what are refs?You need to enable unsafe code in the project properties
set AllowUnsafeBlocks to true
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/ref This doesn't require unsafe
or with tuples:
(a, b) = (b, a)
how do i do that?
set that property to true in your csproj file
The tag will looks like this.
Though as Boxy said, the ref keyword doesn't require unsafe and does pretty much the same thing, its even marshalled into native code as a pointer i believe
I believe the
out
keyword is also marshalled the same as a parameter return typeThis is really unnecessary for what it’s trying to accomplish
I wonder what the point of this is anyway. I feel like an explanation why you need this in general is needed
It's very rare you actually need pointers