Skip to content

Instantly share code, notes, and snippets.

@robertgreiner
Created January 4, 2012 20:24
Show Gist options
  • Save robertgreiner/1561949 to your computer and use it in GitHub Desktop.
Save robertgreiner/1561949 to your computer and use it in GitHub Desktop.
public class SumNumbers
{
private int[] numberList = {1, 2, 4, 8, 16, 32};
public int SumUsingLinq()
{
return numberList.Sum(num => num);
}
public int SumUsingForeach()
{
var sum = 0;
foreach (int num in numberList)
{
sum += num;
}
return sum;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment