Dictionary<int, int> a = new Dictionary<int, int>();
Dictionary<int, float> b = new Dictionary<int, float>();
IDictionary[] dicts = new IDictionary[2];
dicts[0] = a;
dicts[1] = b;
foreach (var d in dicts) {
d.Remove(1);
}
Dictionary<int, int> a = new Dictionary<int, int>();
Dictionary<int, float> b = new Dictionary<int, float>();
IDictionary<int, _IGNORE_>[] dicts = new IDictionary<int, __IGNORE>()[2];
dicts[0] = a;
dicts[1] = b;
foreach (var d in dicts) {
d.Remove(1);
}
C# doesn’t have wildcard generics so I don’t think this is really possible. Dictionary<int, int> and Dictionary<int, float> are entirely different types in the eyes of the compiler and the runtime. The ideal way to do this would be to have a base type of NativeHashMap that doesn’t specify a second generic type constraint which NativeHashMap<K, V> extends from (as I’ve shown above with IDictionary), but obviously you can’t rewrite Unity’s NativeHashMap.