C# return a variable as read only from get; set;
No, there’s no way of doing this. For instance, if you return a List<string> (and it’s not immutable) then callers will be able to add entries. The normal way round this is to return an immutable wrapper, e.g. ReadOnlyCollection<T>. For other mutable types, you may need to clone the value before returning it. Note that … Read more