summing the elements of the an array

  • Thread starter Thread starter neeraj
  • Start date Start date
N

neeraj

Hi

Can any body give me the syntax for summing the elements of the an
array , without looping

thanks
 
I'm not sure what you are looking for. You could update an already computed
sum when you change the value of an array cell. Is this what you meant ? Or
do you meant using the ForEach method (that is your code calls the method
that does the looping for you).

Please be more specific in what you are trying to do (the general answer is
that you have to loop either explicitely or implicitely) or what you are
trying to solve (your current computation is too slow ?)
 
I don't thing you can. If you don't want to do any looping, then
perhaps you could use a DataTable instead of an array and use it's
..Compute() method. Is there a reason you don't want to do a loop?

Thanks,

Seth Rowe
 
Hi Patrice
Thanks for Reply

Actually I am receiving the data from stored procedure in an output
parameter

Like this "23,34,56,322,4445,3234,33344,3334,34344"

and these value also used in whole application as array like this

int [] rupees = {uotParm};

here we can not change the "sql" stored procedure to return the sum
of these value and also can not change the existing "vb.net" code
on whole application

now I want to sum of these value for an purpose, I have already got
the sum of these values by using for each loop but I want to know is
these any method available to get the sum of array aliment by without
use explicit looping.
 
neeraj said:
Hi

Can any body give me the syntax for summing the elements of the an
array , without looping

thanks


WITHOUT looping? I'm not sure that's possible in VB. Maybe in LISP, but
I doubt it in VB...
if you had to you could write an array_sum procedure to HIDE the
looping...
 
Though this would be theorically possible (for example Array.ForEach loops
on an array but is likely more suitable for processing each cell separately
than performing an aggregate operation) it would be more an academic
challenge and I don't really see for now the benefit you expect from this
(you could always create a function that sums an arbitrary array and even
cache the result if the string is the same etc...). Also you'll have likely
anyway to update the code where you want to use this sum while the previous
application was using something else.

Finally LINQ will allow to perform SQL like operations on several sources
including arrays.

For now I would keep the current code unless you can explain what doesn't
work well with it...

----
Patrice

"neeraj" <[email protected]> a écrit dans le message de (e-mail address removed)...
Hi Patrice
Thanks for Reply

Actually I am receiving the data from stored procedure in an output
parameter

Like this "23,34,56,322,4445,3234,33344,3334,34344"

and these value also used in whole application as array like this

int [] rupees = {uotParm};

here we can not change the "sql" stored procedure to return the sum
of these value and also can not change the existing "vb.net" code
on whole application

now I want to sum of these value for an purpose, I have already got
the sum of these values by using for each loop but I want to know is
these any method available to get the sum of array aliment by without
use explicit looping.
 
Back
Top