fbpx

ReadOnly Property

More
4 months 2 weeks ago #1 by Giuseppe Bogetti
ReadOnly Property was created by Giuseppe Bogetti
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

Please Log in or Create an account to join the conversation.

More
4 months 2 weeks ago #2 by Robert van der Hulst
Replied by Robert van der Hulst on topic ReadOnly Property
Giuseppe,
I don't think you can create a readonly auto property.
But try this:
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

or this:
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
This email address is being protected from spambots. You need JavaScript enabled to view it.

Please Log in or Create an account to join the conversation.

More
4 months 2 weeks ago #3 by Giuseppe Bogetti
Replied by Giuseppe Bogetti on topic ReadOnly Property
Robert,
thanks for the explanation. Both work.
Regards Giuseppe

Please Log in or Create an account to join the conversation.