This is kind of hard to explain, so bear with me.
In PHP, if you wanted create a new property in a class, you could without doing anything. The following code would work perfectly.
class testClass
{
public function __construct()
{
}
}
$test = new testClass;
$test->propone = "abc";
echo $test->propone;
I would like to do the same thing, only in C# and with a struct. Is this possible?
Yes, I know, this sounds really clunky. I am trying to simulate a sort of associative array, where there is none. In my environment (NET Microframeworks), hashtables and dictionaries are not supported (yet).
Thanks!
As far as I know there’s no way to add properties dynamically at runtime. Nor is there a way to add properties at compile-time aside from adding them directly to the declaration. In my opinion, this is good as it maintains the type-safety expected from C#.
However, couldn’t you make a primitive hashtable using
List<KeyValuePair<int, List<KeyValuePair<string, object>>>>andString.GetHashCode()? Something like the following (untested and part-pseudocode, but you get the idea):The following should help you with
TryGetValue: