Read-only list of strings

.net, c#, collections, list, readonly

Solution

Depends on your position. `ReadOnlyCollection` works very well when you have an internal modifiable list that needs to be given to some other code that isn't allowed to change the list. For simple code, using `ReadOnlyCollection` is probably overkill. If the code is large and there's a risk some other programmer (or you, down the road) might accidentally attempt to modify the list, then it might be worth it.

In short: don't use `ReadOnlyCollection` idiomatically, use it when it makes sense.

Problem

Is it good to use such approach for keeping read-only list of string, for example, a list of fields in ADO.NET. ``` var list = new System.Collections.ObjectModel.ReadOnlyCollection<string>( new List<string>(4) { "type", "currency", "date", "amount" }); ``` Or this is a superfluous solution?

Original source

Related problems