CSharp examples for System:Array Dimension
Copy one double 2d array to another.
// Licensed under the Apache License, Version 2.0 (the "License"); using System.Collections.Generic; using System;//from www .j a va2 s .c o m public class Main{ /// <summary> /// Copy one double 2d array to another. /// </summary> /// <param name="source">The source array.</param> /// <param name="target">The target array.</param> public static void ArrayCopy(double[][] source, double[][] target) { for(var row=0;row<source.Length;row++) { for(var col=0;col<source[row].Length;col++) { target[row][col] = source[row][col]; } } } /// <summary> /// Copy a double array to a float array. /// </summary> /// <param name="source">The double array.</param> /// <param name="target">The float array.</param> public static void ArrayCopy(double[] source, float[] target) { for (int i = 0; i < source.Length; i++) { target[i] = (float) source[i]; } } /// <summary> /// Copy a float array to a double array. /// </summary> /// <param name="source">The double array.</param> /// <param name="target">The float array.</param> public static void ArrayCopy(float[] source, double[] target) { for (int i = 0; i < source.Length; i++) { target[i] = source[i]; } } /// <summary> /// Copy a 2d array. /// </summary> /// <param name="source">The source.</param> /// <returns>The result.</returns> public static double[][] ArrayCopy(double[][] source) { double[][] result = AllocateDouble2D(source.Length, source[0].Length); for (int row = 0; row < source.Length; row++) { for (int col = 0; col < source[0].Length; col++) { result[row][col] = source[row][col]; } } return result; } /// <summary> /// Copy an array of doubles. /// </summary> /// <param name="source">The source array.</param> /// <param name="sourceIndex">The source index.</param> /// <param name="output">The output array.</param> /// <param name="targetIndex">The output index.</param> /// <param name="size">The size to copy.</param> public static void ArrayCopy(double[] source, int sourceIndex, double[] output, int targetIndex, int size) { //Array.Copy(source, sourceIndex, output, targetIndex, size); Buffer.BlockCopy(source, sourceIndex*DoubleSize,output,targetIndex*DoubleSize,size*DoubleSize); } /// <summary> /// Completely copy one array into another. /// </summary> /// <param name="src">Source array.</param> /// <param name="dst">Destination array.</param> public static void ArrayCopy(int[] src, int[] dst) { Array.Copy(src, dst, src.Length); } /// <summary> /// Completely copy one array into another. /// </summary> /// <param name="src">Source array.</param> /// <param name="dst">Destination array.</param> public static void ArrayCopy(double[] src, double[] dst) { Array.Copy(src, dst, src.Length); } /// <summary> /// Copy an int array. /// </summary> /// <param name="input">The array to copy.</param> /// <returns>The result of the copy.</returns> public static int[] ArrayCopy(int[] input) { var result = new int[input.Length]; ArrayCopy(input, result); return result; } /// <summary> /// Copy a double array. /// </summary> /// <param name="input">The array to copy.</param> /// <returns>The result of the copy.</returns> public static double[] ArrayCopy(double[] input) { var result = new double[input.Length]; ArrayCopy(input, result); return result; } }