你好,感谢阅读。我在使用Foreach循环时遇到了问题。
从我的观察中,foreach的输出只会在所有阶段中执行一次。
这里是我的问题示例:
string[] substrings = Regex.Split(Input, splitPattern);
foreach (string match in substrings)
{
Console.WriteLine("'{0}'" , match + "this is first match ") ;
}
输出结果为:
match 1
match 2
match 3
this is first match
问题1:我的问题是单词“这是第一次匹配”会在所有匹配之后显示,而不是每次匹配之后。我想要单独处理每个匹配。因为我将分配每个匹配的值给一个对象,所以如果有5个匹配,那么就需要5个对象。
问题2:如何单独处理每个匹配(使用或不使用foreach循环)。
谢谢。