I am trying to develop a windows form application in which the user will set an unknown amount of “subcategories”. How can I automate the naming of these new instances.
In case it helps here is what I am going for
private class Category
{
int numberOfCategories = 0;
Category(int categoryNumber)
{
numberOfCategories = categoryNumber;
for (int i = 0; i <= numberOfCategories; ++i)
{
SubCategory *automateThis* = new SubCategory();
}
}
}
private class SubCategory
{
Thank you.
Why would you name them? It will create another problem – how would you access them?
Better approach is to create collection
List<SubCategory>and in such a case you don’t have to worry about naming objects.In case you want to delete SubCategories – you may consider using Dictionary where string may be unique identifier for SubCategory.