KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have a class Bar with a private field containing the reference type Foo . I would like to expose Foo in a public property, but I do not want the consumers of the property to be able to alter Foo ... It should however be alterable internally by Bar , i.e. I can't make the field readonly . So what I would like is: private _Foo; public Foo { get { return readonly _Foo; } } ...which is of course not valid. I could just return a clone of Foo (assumming that it is IClonable ), but this is not obvious to the consumer. Should I change the name of the property to FooCopy ?? Should it be a GetCopyOfFoo method instead? What would you consider best practice? Thanks!
Tags (comma-separated)
Save Edits
Cancel