如何求和数组的元素? [英] How to sum the elements of an array?

查看:64
本文介绍了如何求和数组的元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

汇总数组元素并将

值放入另一个变量的语法是什么?请。

What is the syntax for summing the elements of the an array and putting that
value into another varialble? Please.

推荐答案

Jim

VS.NET 2003语法


昏暗a()As Integer = {1,2,3,4,5}

点心为整数

每个项目为整数

sum + = item

下一页


当然,您可以将Integer更改为您想要的任何数据类型。


如果你不关心For Each,你可以使用你想要的任何其他类型的循环。


希望这有助于

Jay


" Jim" < Ji*@Jones6148.freeserve.co.uk>在消息中写道

news:u1 ************** @ TK2MSFTNGP10.phx.gbl ...
Jim
VS.NET 2003 syntax

Dim a() As Integer = {1, 2, 3, 4, 5}
Dim sum As Integer
For Each item As Integer in a
sum += item
Next

Of course you change Integer to any data type you want.

If you do not care for For Each, you can use any other type of loop you
want.

Hope this helps
Jay

"Jim" <Ji*@Jones6148.freeserve.co.uk> wrote in message
news:u1**************@TK2MSFTNGP10.phx.gbl...
是什么语法求和数组的元素并将
的值放入另一个变量中?请。
What is the syntax for summing the elements of the an array and putting that value into another varialble? Please.



" Jim" < Ji*@Jones6148.freeserve.co.uk> schrieb
"Jim" <Ji*@Jones6148.freeserve.co.uk> schrieb
汇总数组元素的语法是什么?
将该值放入另一个变量中?请。
What is the syntax for summing the elements of the an array and
putting that value into another varialble? Please.




写一个循环。

-

Armin



Write a loop.
--
Armin


你好,


" Jim" < Ji*@Jones6148.freeserve.co.uk> schrieb:
Hello,

"Jim" <Ji*@Jones6148.freeserve.co.uk> schrieb:
对数组的元素求和并将该值放入另一个变量的语法是什么?
What is the syntax for summing the elements of the an array
and putting that value into another varialble?




\\\

Dim aint()As Integer = {4,5,7,99}

点心为整数

Dim i As Integer

For Each i in aint

sum = sum + i

Next i

MsgBox( sum.ToString())

///


-

Herfried K. Wagner

MVP·VB Classic,VB.NET
http://www.mvps.org / dotnet



\\\
Dim aint() As Integer = {4, 5, 7, 99}
Dim sum As Integer
Dim i As Integer
For Each i In aint
sum = sum + i
Next i
MsgBox(sum.ToString())
///

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet


这篇关于如何求和数组的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆