int count = 0, sum = 0;
foreach (int value in data)
{
count++;
if (count > 4) break;
sum += value;
}
If the data is an array/list you could also use the indexer approach, but
you need to worry about 2 end points (the end of the array, and the end of
the desired TOP)...
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.