I realize that since .NET 4.5 that the ReadOnlyCollection<T>
class implements the new interface IReadOnlyCollection<T>
but I am constrained to an older version of the library which doesn't have this.
I would like to know which of the better is considered to be best practice:
public sealed class OptionA {
/// <summary>
/// Gets a read-only list of numbers.
/// </summary>
public ReadOnlyCollection<int> SomeNumbers {
get { return new ReadOnlyCollection<int>(_someNumbers); }
}
...
}
public sealed class OptionB {
/// <summary>
/// Gets a read-only list of numbers.
/// </summary>
public IList<int> SomeNumbers {
get { return new ReadOnlyCollection<int>(_someNumbers); }
}
...
}