C#中累加器函数Aggregate用法实例

本文实例讲述了C#中累加器函数Aggregate用法。分享给大家供大家参考。具体如下:

var shouldExclude = false;
var dirName = dir.Name;
foreach(var pattern in excludePatterns)
{
  shouldExclude = shouldExclude || Regex.Match(dirName, pattern).Success;
}
// 使用Aggregate改写
var dirName = dir.Name;
var shouldExclude = excludePatterns.Aggregate(false, (current, pattern) => current || Regex.Match(dirName, pattern).Success);

希望本文所述对大家的C#程序设计有所帮助。

你可能感兴趣的:(C#中累加器函数Aggregate用法实例)