New to C#, and I am trying to pass Dictionaries with differing Key types to a method:
- Dictionary<long, object>
- Dictionary<string, object>
Is it possible to make my method signature flexible enough to accept both types?
I tried writing my method to be more generic:
public void methodName(IDictionary<object, object> pDictionary)
But I get the error: Error CS1503 Argument 2: cannot convert from 'System.Collections.Generic.Dictionary<long, object>' to 'System.Collections.Generic.IDictionary<object, object>'
I don't totally understand why I cannot implicitly convert long to object, but I supposed it's because it's contained inside a Dictionary. Am I approaching this problem the wrong way, could it be impossible to write a method signature that can handle Dictionaries with differing Key types?