I have the value of Cell and Value in a for loop. I am trying to assign values to around 40 UI Text elements from values obtained from a json file. I am able to read the json file, parse it and find values that I will assign to each of my 40 texts. But I dont want to write bad code by writing as assignment statement for each Ui text…
for (int i = 0; i < BLOCKS.Count; i++)
{
//possible values of Cell are A0, A1, A2 ...
var Cell = currentBLOCKData["cell"];
var Value = currentBLOCKData["value"];
…
Then I have fields named with the same name as Cell
//possible cellName are - A0Text, A1text, A2Text .....
string cellName = Cell + "Text";
I want to assign
A0Text.text = First value in above field - Value
A1Text.text = 2nd value in above field - Value
A2Text.text = 3rd value in above field - Value
How can I make the above assignments without writing 40 such assignment statements? There must be a way I can use the value of the field Value in the above for loop and assign it to A0Text.text, A1Text.text … etc
So for example when i=0, value will be “first value” which I want to assign to A0Text.text. When i=1, , value will be “second value” which I want to assign to A1Text.text…