1 | initial version |
Example code:
public class MyClass {
private ObservableCollection<string> myCollection = new ObservableCollection<string>();
public IReadOnlyList<string> MyReadOnlyCollection {
get { return myCollection.ToList().AsReadOnly(); }
}
}
Note: While this approach provides a read-only view of the collection, it does not protect against modification of the original objects within the collection. If you need to ensure that the elements of the collection cannot be modified, you will need to use immutable objects or create your own read-only collection class that enforces immutability.