在PHP我可以使用foreach循环,使得我能够访问例如键和值既:C#foreach循环
foreach($array as $key => $value)
我有以下代码:
Regex regex = new Regex(pattern);
MatchCollection mc = regex.Matches(haystack);
for (int i = 0; i < mc.Count; i++)
{
GroupCollection gc = mc[i].Groups;
Dictionary<string, string> match = new Dictionary<string, string>();
for (int j = 0; j < gc.Count; j++)
{
//here
}
this.matches.Add(i, match);
}
在//here
我想要match.add(key, value)
但我不知道如何从GroupCollection中获取密钥,在这种情况下应该是捕获组的名称。我知道gc["goupName"].Value
包含匹配的值。
哪个是关键,哪个是价值? – kennytm 2010-02-28 10:09:23