This is a contrived example, but lets say I have declared objects:
CustomObj fooObj;
CustomObj barObj;
CustomObj bazObj;
And I have an string array:
string[] stringarray = new string[] {"foo","bar","baz"};
How can I programmatically access and instantiate those objects using the string array, iterating using something like a foreach:
foreach (string i in stringarray) {
`i`Obj = new CustomObj(i);
}
Hope the idea I'm trying to get across is clear. Is this possible in C#?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…