|
C#的代码- private void DemoDic()
- {
- Dictionary<string, string> dic =
- new Dictionary<string, string>();
- //向字典添加值
- dic.Add("aa", "a1");
- dic.Add("bb", "b1");
- dic.Add("cc", "c1");
- //检测是否存在ee
- if (!dic.ContainsKey("ee"))
- {
- dic.Add("ee", "e1");
- }
- int i;
- //取得字典元素的数目
- i = dic.Keys.Count;
- //宣告String型数组,长度等于字典所含数量
- string[] arrKeys = new string[i];
- string[] arrValues = new string[i];
- dic.Keys.CopyTo(arrKeys, 0);
- dic.Values.CopyTo(arrValues, 0);
- rng1 = Application.get_Range("b6","e6");
- rng1.Value2 = arrKeys;
- rng1 = Application.get_Range("b7", "e7");
- rng1.Value2 = arrValues;
- rng1 = sh.Cells[6, 1];
- rng1.Value2 = "Key";
- rng1 = sh.Cells[7, 1];
- rng1.Value2 = "Value";
- }
复制代码 |
|