I would like to create new instances of my Class called “Item” inside a for statement, but I dont know how to give the name dynamically.
for (i=0; i < Counter; i++)
{
MyClass "XXXX" = Class.method();
}
How can I create 2 strings and give a name?
-for instance-
for(i=0;i<2;i++){
string name + i = "Hello"
}
EDITED
I ve got some proposals to reach my solution which I can create a Dictionary.
var bomItems = new Dictionary<Item, Item>();
for (int i = 0; i < Count; i++)
{
Item bomItem = inn.newItem("Part BOM","add");
bomItems.Add(bomItem + i, bomItem);
}
But I got a reasonable error in “bomItem + i”. that I cannot apply operand ‘+’ . obviously.
Does anyone have any answer for this?
Thank you.
You coud use a collection like
List<String>:Edit Accroding to your comment you want to access the variable by it’s assigned name. Then you should use a
Dictionaryinstead (if the names are unique).For example:
Now you can get the string-value of a given string-key in this way: