ILNumerics Ultimate VSILArrayElementType  Conversion (Array to ILArrayElementType)ILNumerics Ultimate VS Documentation
ILNumerics - The Productivity Machine
Implicitly convert n-dimensional System.Array to ILNumerics ILArray

[ILNumerics Core Module]

Namespace: ILNumerics
Assembly: ILNumerics.Core (in ILNumerics.Core.dll) Version: 4.14.0.0 (4.14.6369.1422)
Syntax

public static implicit operator ILArray<ElementType> (
	Array A
)

Parameters

A
Type: SystemArray
System.Array of arbitrary size

Return Value

Type: ILArrayElementType
If A is null: empty array. Otherwise a new ILNumerics ILArray of the same size as A
Exceptions

ExceptionCondition
InvalidCastExceptionIf the type of the elements in A cannot get converted to ElementType.
InvalidOperationExceptionIf the type of the elements in A is not supported.
Remarks

Elements of A will be copied to elements of the output array (shallow copy). The following element types are supported for A and ElementType: double, float, int, uint, long, ulong, short, ushort, sbyte, byte.

Alternatively, A may consists out of scalar ILArrays (or ILRetArray, ILInArray, ILOutArray) of one of the above element types.

The resulting ILArray will reflect all dimensions of A. Due to the fact that .NET System.Arrays are stored in row major order and ILNumerics stores array in column major (for compatibility with e.g. Matlab and Fortran) the resulting ILArray will have its dimensions reverted! For matrices this corresponds to a matrix transpose.

System.Convert is used for the conversion of elements in A to destination elements. This includes widening and narrowing conversions. When, for example, array elements of type double are provided and ElementType is Int32 the conversion will round the source elements. See the examples below.

[ILNumerics Core Module]

Examples

VB Code Example
'' Elements of System.Value types:
Dim A1 As ILArray(Of Double) = { 1, 2, 3 }  ' provide int elements
Dim A2 As ILArray(Of Double) = { 1.0, 2.9, 3.4, 5.12 }  ' provide double elements
Dim A As Double = 5
Dim B As Double = 6
Dim C As Double = 7

Dim A3 As ILArray(Of Double) = { A, B, C } ' provide double variables

Dim A4 As ILArray(Of Double) = { ILMath.cos(A), ILMath.tan(B) * C, C, 3 } ' provide mixed element types, including scalar ILArray
C# Code Example
ILArray<double> A1 = new[] { 1, ILMath.cos(2.0), 3, 4 };
double B = -1, C = 10;
ILArray<double> A2 = new[] { ILMath.cos(A1[1]), ILMath.tan(B) * C, C, 3 };
// create from multidimensional System.Array 
ILArray<int> A3 = new[,] { { 11, 12, 13 }, { 21, 22, 23 } };
// narrowing conversion: from double to int (note the rounding rules!)
ILArray<int> A4 = new[,] { { 11.9, 12.1, 13 }, { 21.5, 22.5, 23 } };
//<Int32> [3,2]
//    12         22 
//    12         22 
//    13         23
See Also

Reference