I have been trying to create a class which has a property for key value pair, I have tried the Dictionary keyword, but I need something like this:
ClassName clsName = new ClassName(); clsName.PropertyName.Add["Key"] = value; I want it to be dynamic property so I can send any datatype.
clsName["Key"] = value, etc.), and not through anAdd. As such, I'm not completely sure I understand what you're hoping to do. Do you just need to make an indexer on the class?Dictionaryprovides you but allows any type to be stored in the Value? If so than usobjectas the Value of your dictionary, so use a Dictionary<string,object> and not a custom class. Are you trying to make a class that stores a representation of other classes? ThenPropertyName's type should beDictionary<string,object>. Perhaps if you can show us some examples of how you would like to use/address/interact with this hypothetical class, we can show you how its made.