-, object , IDictionary? , , .
, IDictionary 'es ( ..), . , , : IDictionary, ? , object .
:
void WriteMap<TKey, TValue>(IDictionary<TKey, TValue> dict)
{
foreach (var kv in dict)
{
}
}
TKey TValue, , . where .
, string, :
void WriteMap<TValue>(IDictionary<string, TValue> dict)
{
foreach (var kv in dict)
{
}
}
One of the drawbacks of this method is that the compiler must be able to infer type TValueat compile time. If this is not known or the types of values may be different, it may make sense to use IDictionary instead:
void WriteMap(IDictionary dict)
{
foreach (var kv in dict)
{
}
}
Please note that in this case the key is not limited string.
source
share