-1

I'm trying to get my head around this. What's the difference between these 4?

 1. private ObservableCollection<T> _myObservableCollestionOfTs
 2. private readonly ObservableCollection<T> _myObservableCollestionOfTs
 3. private ReadOnlyObservableCollection<T> _myObservableCollestionOfTs
 4. private readonly ReadOnlyObservableCollection<T> _myObservableCollestionOfTs

Thank you for any help :)

1 Answer 1

5
  1. A mutable reference to a mutable collection. The collection's elements can be changed, and the reference pointing to the collection can be reassigned to a different collection or set to null.

  2. An immutable reference to a mutable collection. The collection's elements can be changed, but the reference pointing to the collection cannot.

  3. A mutable reference to an immutable collection. The collection's elements cannot be changed, but the reference can be pointed to a different collection.

  4. An immutable reference to an immutable collection. Neither the collection's elements nor the reference pointing to the collection can be changed.

Read-only collections are simply wrapper classes around ordinary collections that prevent modification of the collection's elements; see the remarks here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.