+ 1
Hey here the REF keyword is the same as a pointer in c++, right?
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Sqr(ref int x) { x = x * x; } static void Main(string[] args) { int a = 3; Sqr(ref a); Console.WriteLine(a); } } }
1 Respuesta
+ 3
The C++ definition that matches that C# ref is:
void Sqr(int &x) { x = x * x; }
The C++ call that matches is:
Sqr(a);
It could be done with pointers, but that wouldn't be identical. You would need to do the following:
void Sqr(int *x) { *x = *x * *x; }
Sqr(&a);