12 Replies
Well, you're never using the
out
parameters
You do Swap(out x, out y)
but then Console.WriteLine($"{a} and {b}")
So either just not have those be out
, or use the x
and y
Also, as a side note, swapping two variables is just (a, b) = (b, a)
in case you were actually intending to use this code lolI did make some mistakes so I change the code. But it is not the point. The point is
long x = (long)a;
makes compiler unhappy. Fact, the x is &a
. How can it say it is unassigned.
I just wanna try to swap the address in the pointer.¯\_(ツ)_/¯ I never had any need to go even remotely close to pointers in C#, so I won't be of help there
If nobody insane enough to use pointers in C# comes by this thread, you could try asking in #advanced
Thank u anyway
you really shouldn't need pointers for anything besides pinvoke stuff
or you're micro-optimizing because you know better than the JIT
out parameters are uninitialized until you assign to them
you have effectively done
as far as the compiler is concerned, you haven't given
a
a value yet
so it won't let you use it
you don't even need pointers to see this errorWindows10CE#8553
REPL Result: Failure
Exception: CompilationErrorException
Compile: 414.713ms | Execution: 0.000ms | React with ❌ to remove this embed.
should Swap's parameters even be
out
?
it's already passing a pointer in, so it's turning into effectively a double pointeryes
thats the point
its swapping pointers
the sane way to write this is
seems unnecessary as a whole
correct!
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.