readonly member (but assignable at constructor time)

Dr.No jckj33 at gmail.com
Fri Apr 27 02:59:16 UTC 2018


In C# you can have a readonly member assignable either at 
declaration or constructor time, like this:

class C
{
   readonly myClass mc;

   this()
   {
     mc = new myClass();
   }


   void doSomething()
   {
     mc = new myClass(); // wrong! result in compiler error, mc is 
readonly
   }
}

Does D have something like this natively or there's a way to do 
so with traits/CTFE at runtime?


More information about the Digitalmars-d-learn mailing list