0
Is there a way to dynamically create/delete objects?
My problem is the following: I want to write a program which manages a database of e.g. persons. It's up to the user to create them. Ergo it is unknown how many objects are needed. Is there a way to "automatically" assign names to the objects (Foo0, Foo1, Foo2...)? I already have te idea to put all objects into a List so the way to delete an object would just be BarList[42].Finalize(); BarList.RemoveAt(42);. Any ideas?
2 Antworten
+ 4
Have you tried using ExpandoObject?
See https://www.oreilly.com/learning/building-c-objects-dynamically
To delete them you can perhaps tag it and use something like
foreach (Label label in Controls.OfType<Label>())
{
if (label.Tag != null && label.Tag.ToString() == "dynamic")
label.Dispose();
}
+ 2
Thanks! That will help me. I'll get into it tommorow.