各配列の要素を足した数字を表示したい。
簡易的に書ける方法を教えて頂けたら幸いです。
実行画面 (メッセージボックス)
1行目の合計 = 15
2行目の合計 = 35
3行目の合計 = 55
4行目の合計 = 75
5行目の合計 = 95
Public Class
Private Sub Button_Display_Click(sender As Object, e As EventArgs) Handles Button_Display.Click
Dim arrayData As Integer(,) = {{1, 2, 3, 4, 5}, {5, 6, 7, 8, 9}, {9, 10, 11, 12, 13}, {13, 14, 15, 16, 17}, {17, 18, 19, 20, 21}}
Dim array1 As Integer = arrayData(0, 0) + arrayData(0, 1) + arrayData(0, 2) + arrayData(0, 3) + arrayData(0, 4) Dim array2 As Integer = arrayData(1, 0) + arrayData(1, 1) + arrayData(1, 2) + arrayData(1, 3) + arrayData(1, 4) Dim array3 As Integer = arrayData(2, 0) + arrayData(2, 1) + arrayData(2, 2) + arrayData(2, 3) + arrayData(2, 4) Dim array4 As Integer = arrayData(3, 0) + arrayData(3, 1) + arrayData(3, 2) + arrayData(3, 3) + arrayData(3, 4) Dim array5 As Integer = arrayData(4, 0) + arrayData(4, 1) + arrayData(4, 2) + arrayData(4, 3) + arrayData(4, 4) MessageBox.Show("1行目の合計" + "=" + CStr(array1) + Environment.NewLine + "2行目の合計" + "=" + CStr(array2) + Environment.NewLine + "3行目の合計" + "=" + CStr(array3) + Environment.NewLine + "4行目の合計" + "=" + CStr(array4) + Environment.NewLine + "5行目の合計" + "=" + CStr(array5)) End Sub
End Class
回答1件
あなたの回答
tips
プレビュー