I have an interesting problem, which is a function that returns a Dictionary<String,HashSet<String>>.
The function converts some primitive structs to a Dictionary Class.
The function is called as follows:
Dictionary<String, HashSet<String>> Myset = new Dictionary<String,HashSet<String>>();
Myset = CacheConverter.MakeDictionary(_myList);
Upon execution of the two lines above, Myset is non-existent to the debugger. Adding a watch results in:
“The name ‘Myset’ does not exist in
the current context”
public Dictionary<String, HashSet<String>> MakeDictionary(LightWeightFetchListCollection _FetchList)
{
Dictionary<String, HashSet<String>> _temp = new Dictionary<String, HashSet<String>>();
// populate the Dictionary
// return
return _temp;
}
The Dictionary _temp is correctly populated by the called function and _temp contains all the expected values.
The problem seems to be with the dictionary not being returned at all.
Examples I could find on the web of functions returning primitive Dictionary<string,string> work as expected.
Two things,
First, don’t initialize the
Mysetwith a new empty instance. The preferred way is to assign the result of the method call.Second, the odds are very strong that you are running in release mode. Typically the compiler will remove any code that is not being used.