Convert One Dimension Array To Three Dimension Array - CSharp System

CSharp examples for System:Array Dimension

Description

Convert One Dimension Array To Three Dimension Array

Demo Code


using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;/*w  ww .  j  av  a2s. c  o  m*/

public class Main{
        public static T[, ,] ConvertOneDArrayToThreeDArray<T>(int x, int y, int z, T[] data)
        {
            T[, ,] result = new T[x, y, z];
            int zPos, yPos, xPos;

            for (int i = 0; i < data.Length; i++)
            {
                zPos = (i % (x * y)) % z;
                yPos = (i % (x * y)) / z;
                xPos = i / (x * y);

                result[xPos, yPos, zPos] = data[i];
            }

            return result;
        }
}

Related Tutorials