Easy C# question - redundant code
Hi! About the next image there is something I have always wondered. Is there a way to make the same function in a much faster way?, like:
string v = "txtAchiev" + cod;
txt = Achievements.v;
Because this code looks very repetitive. How can you identify a variable with a string?
I hope I explained myself correctly.
PS.: I know there is some programming term for this but I don't know it yet.

Answer by mikelortega · Dec 14, 2015 at 12:39 PM
I guess you probably have this somewhere in your code:
     string txtAchiev0;
     string txtAchiev1;
     string txtAchiev2;
     string ...
Instead, use an array:
     string txtAchiev[21];
Then in your code you can just:
 string txt = txtAchiev[cod];
Your answer
 
 
             Follow this Question
Related Questions
Only make changes to one prefab instance 2 Answers
making snake game 0 Answers
AudioSource missing reference after SceneManager.LoadScene 2 Answers
Any way to set AnimatorOverrideController's animation clips programatically? 1 Answer
How can I make my random switch statement not select the same object twice in a row 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                