Array list
how to sum of even number in array list ?
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Karan Patel120 reputationPosted Mar 3, 2010, 8:00 PM EST
int sum = 0;
for (int i = 0; i < arr.Length; i++)
{
if (arr[i] % 2 == 0)
{
sum += arr[i];
}
}
MessageBox.Show(sum.ToString());
theLizardRank #1,079 · 1.8K reputationPosted Mar 3, 2010, 11:06 PM EST
for (int i = 0; i < arr.Length; i++)
{
sum += (arr[i] % 2 == 0) ? arr[i] : 0;
}