如何创建一个类型为string的变量,其名称为文本框中写入的内容 [英] How do I create a variable of type string with the name of whats written on the textbox
本文介绍了如何创建一个类型为string的变量,其名称为文本框中写入的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设一个人在文本框中输入苹果我想让它变成一个变量
string apple = apple is created
或者,如果某人在注册屏幕上的不同文本框中输入用户名和密码,则代码
if(textbox.Text =Username&& textbox2。 text ==密码)
{
}
是自动创建
我尝试过:
So suppose a person enters apple in the textbox i want to make it so a variable
string apple = apple is created
or if a person enters a user name and password in different textboxes on a registeration screen the code
if(textbox.Text = "Username" && textbox2.text == "Password")
{
}
is automatically created
What I have tried:
string textbox1.text = textBox1.Text;
推荐答案
你没有。简单来说,变量名只存在于编译时。
如果你想要一个变量来保存一个值,你通常会把这些东西保存在一个字典中采集。在你所谈论的意义上,它不是一个真正的变量,但输入的名称成为集合中的关键,指向相关的值,称为键/值对。
You don't. In simple terms, variable names only exist until compile-time.
If you want a "variable" to hold a value, you would normally keep such things in a Dictionary collection. It's not a true variable in the sense you're talking about, but the name entered becomes a "key" in the collection, pointing to the associated value, known as a key/value pair.
这篇关于如何创建一个类型为string的变量,其名称为文本框中写入的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文