<p>My class contains a <code>Dictionary&lt;T, S&gt; dict</code>, and I want to expose a <code>ReadOnlyCollection&lt;T&gt;</code> of the keys. How can I do this without copying the <code>Dictionary&lt;T, S&gt;.KeyCollection dict.Keys</code> to an array and then exposing the array as a <code>ReadOnlyCollection</code>?  </p>

<p>I want the  <code>ReadOnlyCollection</code> to be a proper wrapper, ie. to reflect changes in the underlying Dictionary, and as I understand it copying the collection to an array will not do this (as well as seeming inefficient - I don't actually want a new collection, just to expose the underlying collection of keys...). Any ideas would be much appreciated!</p>

<p>Edit: I'm using C# 2.0, so don't have extension methods such as .ToList (easily) available.  </p>

If you really want to use ReadOnlyCollection<T>, the issue is that the constructor of ReadOnlyCollection<T> takes an IList<T>, while the KeyCollection of the Dictionary is only a ICollection<T>.
So if you want to wrap the KeyCollection in a ReadOnlyCollection, you'll have to create an adapter (or wrapper) type, implementing IList<T>, wrapping the KeyCollection. So it would look like:
```
```
var dictionary = ...;
var readonly_keys = new ReadOnlyCollection<T> (new CollectionListWrapper<T> (dictionary.Keys)
);
```
```
Not very elegant though, especially as the KeyCollection is already a readonly collection, and that you could simply pass it around as an ICollection<T> :)