Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>No, but a wrapper is rather trivial:</p> <pre><code>public class ReadOnlyDictionary&lt;TKey, TValue&gt; : IDictionary&lt;TKey, TValue&gt; { IDictionary&lt;TKey, TValue&gt; _dict; public ReadOnlyDictionary(IDictionary&lt;TKey, TValue&gt; backingDict) { _dict = backingDict; } public void Add(TKey key, TValue value) { throw new InvalidOperationException(); } public bool ContainsKey(TKey key) { return _dict.ContainsKey(key); } public ICollection&lt;TKey&gt; Keys { get { return _dict.Keys; } } public bool Remove(TKey key) { throw new InvalidOperationException(); } public bool TryGetValue(TKey key, out TValue value) { return _dict.TryGetValue(key, out value); } public ICollection&lt;TValue&gt; Values { get { return _dict.Values; } } public TValue this[TKey key] { get { return _dict[key]; } set { throw new InvalidOperationException(); } } public void Add(KeyValuePair&lt;TKey, TValue&gt; item) { throw new InvalidOperationException(); } public void Clear() { throw new InvalidOperationException(); } public bool Contains(KeyValuePair&lt;TKey, TValue&gt; item) { return _dict.Contains(item); } public void CopyTo(KeyValuePair&lt;TKey, TValue&gt;[] array, int arrayIndex) { _dict.CopyTo(array, arrayIndex); } public int Count { get { return _dict.Count; } } public bool IsReadOnly { get { return true; } } public bool Remove(KeyValuePair&lt;TKey, TValue&gt; item) { throw new InvalidOperationException(); } public IEnumerator&lt;KeyValuePair&lt;TKey, TValue&gt;&gt; GetEnumerator() { return _dict.GetEnumerator(); } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return ((System.Collections.IEnumerable)_dict).GetEnumerator(); } } </code></pre> <p>Obviously, you can change the this[] setter above if you want to allow modifying values. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload