Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VB.NET Array Arithmetic

Is there a built-in way to multiply every member of an array by some number in-place?

Example:

Dim volts () as Double = {1.243, 0.534, 5.343, 2.223, 4.334}
Dim millivolts (4) as Double = volts.MultiplyEachBy(1000) 'something like this
like image 312
Steven Avatar asked Feb 23 '10 16:02

Steven


1 Answers

You can use the Array.ConvertAll method.

Array.ConvertAll(volts, Function(x) x * 1000)

EDIT

There is a small error in the sample code which needs to be corrected for the above to compile. Remove the explicit size (4) from the variable type

Dim volts() As Double = {1.243, 0.534, 5.343, 2.223, 4.334}
like image 93
JaredPar Avatar answered Oct 14 '22 03:10

JaredPar