我有一个关于 Dictionary<string, int>
的工作示例。现在我需要将这个 Dictionary
设置为 private Dictionary
并检查其值。
目前,我的代码如下:
protected void btnSubmit_Click(object sender, EventArgs e)
{
Dictionary<string, int> docTypeValue = new Dictionary<string, int>();
docTypeValue.Add("OSD", 1);
docTypeValue.Add("POD", 2);
docTypeValue.Add("REC", 3);
docTypeValue.Add("CLAINF", 4);
docTypeValue.Add("RATE", 5);
docTypeValue.Add("OTHER", 6);
docTypeValue.Add("CARINV", 7);
docTypeValue.Add("PODDET", 8);
docTypeValue.Add("BOLPO", 9);
litText.Text = docTypeValue[txtDocType.Text].ToString();
}
这个工作正常运行。我需要使用一个属性吗?例如下面的代码:
private Dictionary<string, int> DocTypeValue
{
get;
set;
}
我该如何重构上面的代码以创建建议的
private Dictionary
?
Dictionary<string, int> docTypeValue = new Dictionary<string, int>();
,然后使用ctrl+x
剪切并粘贴到方法上方 :) - Sriram Sakthivel