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