OT: C# now has ref and const ref return

Simen Kjærås simen.kjaras at gmail.com
Tue Aug 6 11:45:48 UTC 2019


On Tuesday, 6 August 2019 at 09:54:49 UTC, XavierAP wrote:
> (This makes it look at first like it's allowing ref local 
> variable declarations like C++, but I understand -- haven't 
> played with it yet -- that in reality it's only allowed at the 
> left side of calls to ref return methods.)

It seems to me C# ref variables are very much like C++ ref 
variables (tested and works ;on my machine):

using System.Diagnostics;

class C
{
     static void Main()
     {
         var i = 3;
         ref int ir = ref i;
         ir = 17;
         Debug.Assert(i == 17);
     }
}

Can't have const references to literal values (e.g. const int& i 
= 13;) like in C++, though.

--
   Simen



More information about the Digitalmars-d mailing list