Hi,
is there the possibility to declare an auto property of a class as readonly ?
IF yes, can you share a little sample because I tried various combinations and all failed
Regards Giuseppe
ReadOnly Property
ReadOnly Property
Giuseppe,
I don't think you can create a readonly auto property.
But try this:
or this:
I don't think you can create a readonly auto property.
But try this:
Code: Select all
CLASS Example
// Not strictly readonly but can only be changed inside class
PROPERTY NAME AS STRING AUTO GET PRIVATE SET
CONSTRUCTOR(cName AS STRING)
SELF:Name := cName
END CLASS
Code: Select all
CLASS Example2
// Really readonly. Can only be assigned in the constructor
PROPERTY NAME AS STRING GET _Name
PRIVATE INITONLY _Name AS STRING
CONSTRUCTOR(cName AS STRING)
SELF:_Name := cName
END CLASS
XSharp Development Team
The Netherlands
robert@xsharp.eu
The Netherlands
robert@xsharp.eu
- orangesocks
- Posts: 40
- Joined: Thu Nov 12, 2015 2:41 pm
ReadOnly Property
Robert,
thanks for the explanation. Both work.
Regards Giuseppe
thanks for the explanation. Both work.
Regards Giuseppe