简体   繁体   中英

Name a variable by combining the contents of 2 variable

I want when the user clicks the button a new variable will be created like now a variable should be created with the name 1time and when the user clicks again a new variable will be created with the name of 2time how can i do that please help me i am a beginner

int alltime = 1;
        private void button1_Click(object sender, EventArgs e)
        {
        
        int alltime+time;
        alltime += 1;

        }
    }
}

Hello and welcome to stackoverflow.

There is no way to name a variable at runtime. C# does not support something like this. Names have to be choosen upfront.

If you want to match a value to a dynamic key, you could go with KeyValuePair<string, whateveryouwant> or a Dict<string, whateveryouwant>.

And to be honest. There is no case I can think of where it should be necessary to you use a dynamicly named variable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM