Is there any another shortcut rather than giving all the arrays seperately like below in for each loop

is there any another shortcut rather than giving all the arrays seperately like below in for each loop
{Numbers(0)+Numbers(1)+Numbers(2)+Numbers(3)+Numbers(4)+Numbers(5)+Numbers(6)}

Hi @Bhagyaraj_Digumarthi

i assume you sum all the items in the array,

numbers.Sum(function(d) cint(d))

Thanks

Hi @Bhagyaraj_Digumarthi ,

Here is the solution.
Sum
Sum

Hope this will help you. Thank you.

@prasath_S You are correct.

2 Likes

Hi

Here you are passing the value as a sum which is a individual value
So first I would like to suggest that we won’t be in need of For each loop first

  1. If we are passing the array variable Numbers, then we need for each loop

  2. If we want the sum of array values then we can directly use writeline or any activity where you want to pass that sum value
    With this expression

YourArrayVar.Sum(function (x) Convert.ToInt32(x)).ToString

  1. Sometimes there can be some blank values in the array and in that case we need to do a validation before summation like this

Yourarrayvar.Sum(Function (x) If(String.IsNullOrEmpty(x.ToString), 0, x) )

If it’s empty then will pass 0 as value or it will pass the actual Numerical value

Cheers @Bhagyaraj_Digumarthi

1 Like

YourArrayVar.Sum(function (x) Convert.ToInt32(x)).ToString–is it LINQ?

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.