I want to create a Dictionary with TKey as string and the TValue to be from type which is not know at compile time.
Let’s say for example I have a function
createDict(Type type)
{
Dictionary<string, {here's the type from the func. argument}> dict = new Dictionary..
}
Is this scenario possible or I’m missing something very basic ?
Make the method generic:
Though you may want the return type to also be
Dictionary<string,T>and add constrains to the generic type parameter.You would call it as:
The above assumes the type can be passed in during compile time.