C# return a variable as read only from get; set;

后端 未结 7 2308
不思量自难忘°
不思量自难忘° 2021-02-02 07:30

I swear I have seen an example of this but have been googling for a bit and can not find it.

I have a class that has a reference to an object and need to have a GET; met

7条回答
  •  暖寄归人
    2021-02-02 07:55

    This isn't possible. Get and set accessors to reference types get and set the reference to the object. You can prevent changes to the reference by using a private (or internal) setter, but you cannot prevent changes to the object itself if it's exposed by a getter.

提交回复
热议问题