Clarification in array variable

Last Reply on Apr 16, 2012 09:58 AM By vinayak

Posted on Apr 16, 2012 06:28 AM

Hi

I am having a list of number in an array.

I need a code to add the numbers that ends with 5.

for example, I am having the following numbers in an array.

Let it be

1,15,5,25,14,10 

The result of the above example is 45 .

Here I am adding 15 + 5 + 25 since these numbers are end with 5.

Thanks in advance.

You are viewing reply posted by: vinayak on Apr 16, 2012 09:58 AM.
Posted on Apr 16, 2012 09:58 AM

refer following code

 

    string[] arr = { "1", "15", "5", "25", "14","10" };        int result = 0;
        for (int i = 0; i <= arr.Length - 1; i++)        {
            if (arr[i].EndsWith("5"))            {
                result = result + Convert.ToInt32(arr[i]);            }        }