array list
how to sum of even number in array list ?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
theLizardPosted Mar 4, 2010, 4:06 AM
for (int i = 0; i < arr.Length; i++)
{
sum += (arr[i] % 2 == 0) ? arr[i] : 0;
}
Karan PatelPosted Mar 4, 2010, 1:00 AM
int sum = 0;
for (int i = 0; i < arr.Length; i++)
{
if (arr[i] % 2 == 0)
{
sum += arr[i];
}
}
MessageBox.Show(sum.ToString());