【发布时间】:2010-02-28 10:04:48
【问题描述】:
在 PHP 中,我可以使用 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 包含匹配的值。
【问题讨论】:
-
哪个是key,哪个是value?