How to make a ReadOnlyCollection from a HashSet without copying the elements?
<p>I have a private <code>HashSet&lt;string&gt;</code> which is the backing field of a read-only property which should return a read-only collection such that callers cannot modify the collection. So I tried to:</p>

<pre><code>public class MyClass
{
    private readonly HashSet&lt;string&gt; _referencedColumns;

    public ICollection&lt;string&gt; ReferencedColumns { 
        get { return new ReadOnlyCollection&lt;string&gt;(_referencedColumns); }
    }
</code></pre>

<p>This does not compile as <code>ReadOnlyCollection</code> accepts a <code>IList&lt;T&gt;</code> which is not implememted by <code>HashSet&lt;T&gt;</code>. Is there another wrapper I can use to save me from copy the items? For my purpose it is enough to just return something implementing <code>ICollection&lt;T&gt;</code> (instead of <code>IList&lt;T&gt;</code>) which is implemented by the <code>HashSet&lt;T&gt;</code>.</p>