コード例 #1
0
        public static void ReplaceAllPositive(int [,,] array)
        {
            int numberOfReplaces = 0;

            for (int i = 0; i < array.GetLength(0); i++)
            {
                for (int j = 0; j < array.GetLength(1); j++)
                {
                    for (int n = 0; n < array.GetLength(2); n++)
                    {
                        if (array[i, j, n] > 0)
                        {
                            numberOfReplaces = numberOfReplaces + 1;
                            array[i, j, n]   = 0;
                        }
                    }
                }
            }
            ConsoleHelper.WriteText($"Array after replacing:");
            ConsoleHelper.WriteThreeDimensionalArray(array);
            ConsoleHelper.WriteText($"Replaced: {numberOfReplaces} values.");
        }
コード例 #2
0
        public static int[, ,] GenerateThreeDimensional()
        {
            Random rnd = new Random();
            int    x   = rnd.Next(1, 10);
            int    y   = rnd.Next(1, 10);
            int    z   = rnd.Next(1, 10);

            int[, ,] newarray = new int[x, y, z];
            for (int i = 0; i < newarray.GetLength(0); i++)
            {
                for (int j = 0; j < newarray.GetLength(1); j++)
                {
                    for (int n = 0; n < newarray.GetLength(2); n++)
                    {
                        newarray[i, j, n] = rnd.Next(-10, 10);
                    }
                }
            }
            ConsoleHelper.WriteText($"New array is:");
            ConsoleHelper.WriteThreeDimensionalArray(newarray);
            return(newarray);
        }