+ 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); } } }

30th Dec 2018, 10:24 PM
Daniel
1 ответ
+ 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);
31st Dec 2018, 2:23 AM
John Wells
John Wells - avatar