fbpx
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: ReadOnly Property

ReadOnly Property 9 months 2 weeks ago #6079

  orangesocks's Avatar Topic Author orangesocks Offline Posts: 32
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.

ReadOnly Property 9 months 2 weeks ago #6080

  robert's Avatar robert Offline Posts: 1001
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.

ReadOnly Property 9 months 2 weeks ago #6081

  orangesocks's Avatar Topic Author orangesocks Offline Posts: 32
Robert,
thanks for the explanation. Both work.
Regards Giuseppe

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

  • Page:
  • 1