Dictionary as parameter, where the Value-Type is irrelevant

Posted by aaginor on Stack Overflow See other posts from Stack Overflow or by aaginor
Published on 2010-03-16T10:29:14Z Indexed on 2010/03/16 10:36 UTC
Read the original article Hit count: 129

Filed under:

Hi folks,

I have a function, that returns the next higher value of a Dictionary-Keys-List compared to a given value. If we have a Key-List of {1, 4, 10, 24} and a given value of 8, the function would return 10.

Obviously the type of the Value-Part of the Dictionary doesn't matter for the function, the function-code for a

Dictionary<int, int> 

and

Dictionary<int, myClass> 

would be the same.

How has the method-head have to look like, when I want to call the function with any Dictionary, that has int as key-Type and the value-Type is irrelevant?

I tried:

private int GetClosedKey(Dictionary<int, object> list, int theValue);

but it says that there are illegal arguments, when I call it with a Dictionary. I don't want to copy'n'paste the function for each different value-type that my function may be called. Any idea, how to accomplish that?

Thanks in advance, Frank

© Stack Overflow or respective owner

Related posts about c#