I have these 2 objects, a dictionary, and a method
public abstract class Thing {}
public class Star : Thing {}
Dictionary<int, Star> dictStar;
public void listBoxAdd (Listbox listBox, Dictionary<int, Thing> thingDict){}
I want to call the method with dictStar. I tried a bunch of stuff to cast my dictionary and nothing I tried worked. I would think this should work, but the compiler disagrees.
listBoxAdd (starList, ( Dictionary<int, Thing>) dictStar);
I get an error CS0030 that c# can not convert a dictionary of star to a dictionary of thing.
There are several other classes based on thing and my design requires dictionaries of them being passed to methods that will work on the fields in Thing. There are several times I have methods that only need to access stuff that is defined in Thing.
I have no problem casting a Star to a Thing, but I have the problem with the dictionary. I tried having the method take a dictionary of int, object and I could call but in the method I could not cast the Dictionary of Objects to Tings.
If I use Star Dictionaries in both the method and call it works fine.
I even use a base class of Thing with Star derived from it.
I come from the old days of 64K mainframes and am constantly thinking of memory usage and machine cycles so, in addition to being inelegant, going through the dictionary and calling with every element, though it will work, seems like a bad idea.
I know a lot of the rules are used to allow c# to clean up unused stuff in memory, but there is no danger of the elements going away during the call.