Access class field using string?

I have a class named CDB which has fields from a to g and i have a string array named numeStrat that can be accessed so that numeStrat[1]=“a”,numeStrat[2]=“b”…

I take a regular string named tmp and i assign the value which i need from the string array, example: tmp=numeStrat[1]; this will make tmp take the value “a”. Now i want to access the class field using the tmp string which is now “a” (CDB.tmp or something).

Make tmp static

You should not do this!

There is a very good reason for why strings and the names of variables are not the same thing. In essence, this has to do with what happens when you do something wrong, as it gets really hard to debug what’s going on.

Having variables with names such as “a” or “b” is a bad idea too - those names tell you nothing about what the variables are, and how they’re supposed to be used. “strArray” is also the worst name for an array of strings, as every string array could have that name.

Don’t do whatever you’re trying to do. I’d suggest that you instead post what you’re trying to achieve, and the community can give you hints about how to do about doing that.

Finally, you can do this through something called reflection, but that’s a really, really bad idea too, and the topic is advanced enough that you shouldn’t be trying to use it if you need to come by Unity Answers. Again, you should not do this.