编码方法和字典的用法

时间:2012-08-23 19:03:31

标签: c# dynamic dictionary key-value key-value-coding

我有这组常量。

private const string A1KEY = 'a1';
private const string A1VALUE = 'AONE';
private const string B1KEY = 'b1';
private const string B1VALUE = 'BONE';
private const string C1KEY = 'c1';
private const string C1VALUE = 'CONE';
private const string D1KEY = 'd1';
private const string D1VALUE = 'DONE';

我收到表格的输入。

string input = 'a1,b1,d1';

所以,根据这个输入......我的目标是生成一个动态脚本,其中包含输入中接收的键的相应值。

我打算,

1)将键值对添加到词典中 2)将字典键与输入字符串进行比较 3)为收到的密钥选择各自的值 4)并将该列表发送到生成脚本的方法。

public string GenerateDynamicScript (...)
{
StringBuilder appndScript = new StringBuilder();

appndScript.Append ("alert('the value is <variable>'"); }

这是一种正确的方法吗?代码示例会很有帮助。

实现这一目标的有效方法是什么?

1 个答案:

答案 0 :(得分:1)

Dictionary<string string> myDict = new Dictionary<string, string>();

// Add your values

string keys[] = input.split(',');

return myDict[keys[0]];

这不是整个实现,但这应该让你开始。

我的C#有点生疏,可能编译也可能不编译。

相关问题