我如何动态地命名在C#中的变量? [英] How do I name variables dynamically in C#?
本文介绍了我如何动态地命名在C#中的变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法来动态命名变量?
Is there a way to dynamically name variables?
我需要做的是从输入文件采取的变量名的列表,并创建了这些名字的变量。这可能吗?
What I need to do is take a list of variable names from an input file and create variables with those names. Is this possible?
是这样的:
Variable <dynamic name of variable here> = new Variable(input);
假设我已经有了变量
类的照顾,和变量的名称是包含在一个名为字符串 strLine中
。
Assume that I already have the Variable
class taken care of, and the name of the variable is contain in a string called strLine
.
推荐答案
使用词典&LT;字符串变量方式&gt;
例如
var vartable = new Dictionary<string, Variable>();
vartable[strLine] = new Variable(input);
这篇关于我如何动态地命名在C#中的变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文