title: Why do C# TryAdd, TryRemove, TryGetValue return null sets when they fail?
body: <p><em><strong>Why do the Dictionary methods return a null set when they fail?</strong></em></p>
  <blockquote>
  <p>If the answer is &quot;what do you expect them to return???&quot; I guess I was
  expecting an empty HashSet that I can run methods like Count or
  GetEnumerator on. Without getting an exception.</p>
  <p>Maybe my question is really, should I catch an exception, make the return value not null and then return it?</p>
  </blockquote>
  <p>I looked at <a href="https://stackoverflow.com/questions/14034873/dictionary-trygetvalue-nullreferenceexception">this question</a> but my dictionary is not null when I call Add(), Remove() or TryGetValue()</p>
  <p>Yes this is for a programming assignment, but the data structure is my choice, to represent a graph using two ConcurrentDictionaries.</p>
  <p>When a test runs:</p>
  <pre><code>DependencyGraph t = new DependencyGraph();
  Assert.IsFalse(t.GetDependees(&quot;x&quot;).GetEnumerator().MoveNext());
  </code></pre>
  <p>My method runs:</p>
  <pre><code>    public IEnumerable&lt;string&gt; GetDependees(string s)
      {
          HashSet&lt;String&gt; valuesForKey = new HashSet&lt;String&gt;();
          dependeeGraph.TryGetValue(s, out valuesForKey);
          return valuesForKey;
      }
  </code></pre>
  <p>And when it hits <code>.GetEnumerator().MoveNext()</code> on the return value I get nullReferenceException.</p>