foreach (KeyValuePair<string, string> a in data)
{
}
因为涉及到修改,用FOR行不行?怎么用呢
{
}
因为涉及到修改,用FOR行不行?怎么用呢
解决方案 »
- 有关编写浏览器
- VS项目编译的时候,错误信息和警告信息是本地的那个文件?
- 怎样判断一个IP地址是Internet地址还是Intranet地址
- 如何控制删除条件
- 有谁在开发服务器控件时,继承过IPostBackDataHandler 和 IPostBackEventHandler接口,什么情况下要继承他???????????
- web页面中怎样将查询的结果导出到可编辑的Excel要求源码提供!!asp.net
- 除了关闭事件有来源一说.别的东西有吗.?
- 怎么实现在vs.net工具栏里的那种下拉按钮!???????????????
- 如何开发虚拟打印机?请教大家!
- 不能在Visual C#中创建Web应用程序,一定给分
- 小弟遇到急切难题。。。万望各位大大救命!
- 关于WinForm的送分题,各位帮帮忙吧,急需。
{
KeyValuePair<string, string> a = data[i];
}
{
KeyValuePair<string, string> a = data[i];
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace ConsoleApplication1
{
class Program
{
static void Main()
{
//初始化dictionary对象
Dictionary<string, string> dict1 = new Dictionary<string, string>();
dict1.Add("LeftValue", "1"); List<DictValue> listDict = new List<DictValue>();
Dictionary<string, string>.KeyCollection kc = dict1.Keys;
Dictionary<string, string>.ValueCollection vc = dict1.Values;
foreach(string k1 in kc)
foreach (string v1 in vc)
{
DictValue dv = new DictValue();
dv.key = k1;
dv.value = v1;
listDict.Add(dv);
}
// 接下来,使用映射对象 listDict进行遍历 for (int i = 0; i < listDict.Count; i++)
{
Console.WriteLine("key:{0},value:{1}", listDict[i].key, listDict[i].value);
} Console.ReadLine();
}
} class DictValue
{
public string key="";
public string value="";
}}
如果只是想修改value的话
可以使用
Dictionary<string, string> a = new Dictionary<string,string>();
foreach( string key in a.Keys)
{
a[key] = ...
}
如果想删除 使用Remove.
哎,技术界呀的人,再说一一猪头们,这样做到底行不行你息试一下再说不要想当然
Dictionary<string, string> a = new Dictionary<string,string>(); foreach( string key in a.Keys) { a[key] = ... }
dict.Add(1, "helo");
dict.Add(2, "helo");
int[] keys = new int[dict.Count];
dict.Keys.CopyTo(keys, 0);
foreach (int key in keys)
{
Response.Write("key"+key.ToString()+":" + key.ToString());
dict.Remove(key);
// Response.Write("key" + key.ToString() + ":" + dict[key]);
}