如何在VB.NET中的维数组[4x2]中使用绝对值(abs) [英] How do I use the absolute value (abs) in a dimension array [4x2] in VB.NET

查看:192
本文介绍了如何在VB.NET中的维数组[4x2]中使用绝对值(abs)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

之前我有一个问题以及如何在数组中使用它。



一切都还好,现在我想在维数组中制作abs(我知道我已经打开过关于维数组的先前问题,但是......) />


所以,我想进行abs计算并将其存储到新的[4x2]数组中。我做错了什么?



谢谢



我尝试了什么:



Hello to all,
Previously I had a question about abs math function and how can I use it in an array.

Everything is ok ,now I want to make abs in an dimension array (I know I had opened the previously question about dimension array, but ...)

So, I want to make the abs calculation and store it to a new [4x2] array. What am I doing wrong?

Thank you

What I have tried:

Dim spalings As Double(,) = {{-1, 2.0}, {-3, 4}, {-5, 6}, {-0.7, 8}}
Dim spalins2 As Double(,) = New Double((spalings.Length - 1), (spalings.Length - 1)) {}
    For x As Integer = 0 To spalings.Length - 1
         For j As Integer = 0 To spalings.Length - 1
              spalins2(x, j) = Math.Abs(spalings(x, j))
         Next j
    Next x

推荐答案

嗯...你知道什么长度返回多维数组,是吗?

每次调用它都会返回相同的值吗?

Um...you do know what Length returns for a multidimension array, yes?
And that it will return the same value each time you call it?
Dim spalins2 As Double(,) = New Double((spalings.Length - 1), (spalings.Length - 1)) {}



And

For x As Integer = 0 To spalings.Length - 1
     For j As Integer = 0 To spalings.Length - 1

那么你认为它有多少元素调查?

答案是:它返回元素总数 - 在你的情况下为8。

所以你的循环将执行8 * 8次,并尝试看看64个元素。所以你的程序会崩溃。

你需要查看GetUpperBound方法: Array.GetUpperBound方法(Int32)(系统) [ ^ ]

So how many elements do you think it's going to investigate?
The answer is: it returns the total number of elements - in your case "8".
So your loop will execute 8 * 8 times, and try to look at 64 elements. So your program will crash.
You need to look at the GetUpperBound method: Array.GetUpperBound Method (Int32) (System)[^]


这篇关于如何在VB.NET中的维数组[4x2]中使用绝对值(abs)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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