如何在 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);
假设我已经处理了 Variable
类,并且变量的名称包含在名为 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
.
推荐答案
使用 Dictionary
.
例如
var vartable = new Dictionary<string, Variable>();
vartable[strLine] = new Variable(input);
这篇关于如何在 C# 中动态命名变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文