I want to create a dictionary to associate a string to a class for example:
"dog" -> Dog class
"cat" -> Cat class
so I tried this
public Dictionary<String, Type> dic = new Dictionary<String, Type>();
dic.Add("dog", Dog);
but Add doesn't accept Dog
.
So what's the syntax ?
You should use the typeof
operator to get the corresponding Type
object:
public Dictionary<String, Type> dic = new Dictionary<String, Type>();
dic.Add("dog", typeof(Dog));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With