If you have *ANY* kind of collection object as a member of your class, then you could add to it as needed.
Example: Say you have a class that describes these "properties" that you want to dynamically add. Maybe a property has a name, a type, and a value. For simplicity, we'll say that the value is held as just an Object and you will write code to cast the various values to their correct types.
Code:
class MyProperty
{
public String name;
public DataTypeDescriptor type;
public Object value;
}
(I'm keeping this simple, just making everything public. In "real life" you'd probably write get/set methods and keep the data members private. But that's really just syntactic sugar.)
Okay, so now you write your class that needs to be able to hold an arbitrary number of these dynamically added MyProperty objects.
Code:
class MyHolder
{
// I'm just making up some other members of the class...
public DateTime whenCreated;
public int timeToLive;
public String password; // silly stuff
// but then here is your collection:
List<MyProperty> properties;
// and you could have methods such as
void AddProperty( MyProperty toAdd )
{
properties.Add( toAdd );
}
// or maybe:
void AddProperty( String nm, DataTypeDescriptor dtd, Object val );
{
// really should have a constructor for MyProperty, but even without one
// we can do it the brute force way:
MyProperty prop = new MyProperty( );
prop.Name = nm;
prop.Type = dtd;
prop.Value = val;
properties.Add( prop );
}
// and much much more...
}
If you think about it, the .NET framework is just chock full of collections such as this. Just as one for-instance, DataReader and DataTable and DataRow objects are all implemented, under the covers, with some kind of collection. And of course when you use a method such as FindControl( ), you are really just looking for a particular object in the collection of objects that represent the HTML display. And and and...
At this point, maybe the best thing I can suggest is that you think about buying and reading this book:
http://www.wrox.com/WileyCDA/WroxTit...470261293.html
It's probably the best way to approach C#, much better than starting from building websites, I think. And it's going to cover these kinds of subjects in a lot more depth than anyone can, just posting messages in these silly little windows.