这是好事还是坏事:
foreach (Match match in serverNameRegex.Matches(loginPage))
{
....
}
或者我应该这样使用它以获得更快的速度:
MatchCollection matches = serverNameRegex.Matches(loginPage);
foreach (Match match in matches)
{
...
}
最佳答案
只要 MatchCollection
不能为空,我就说这是你的选择。
但如果结果为 null 而您没有事先检查它,您将遇到 NullReferenceException
。
关于C# - foreach 循环 - 良好实践,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8412791/