lambda表达式foreach循环

NSN*_*NSN 1 .net c# lambda

我有以下代码

int someCount = 0;

for ( int i =0 ; i < intarr.Length;i++ )
{
   if ( intarr[i] % 2 == 0 )
   { 
       someCount++;
       continue;
   }
   // Some other logic for those not satisfying the condition
}
Run Code Online (Sandbox Code Playgroud)

是否可以使用Array.Where或Array.SkiplWhile中的任何一个来实现相同的功能?

foreach(int i in intarr.where(<<condtion>> + increment for failures) )
{
      // Some other logic for those not satisfying the condition    
}
Run Code Online (Sandbox Code Playgroud)

nne*_*neo 6

使用LINQ:

int someCount = intarr.Count(val => val % 2 == 0);
Run Code Online (Sandbox Code Playgroud)