示例#1
0
        public static T[, ,] Resize <T>(this T[, ,] source, int newLengthA, int newLengthB, int newLengthC)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            int upperSA = source.GetUpperBound(0),
                upperSB = source.GetUpperBound(1),
                upperSC = source.GetUpperBound(2);

            int lowerSA = source.GetLowerBound(0),
                lowerSB = source.GetLowerBound(1),
                lowerSC = source.GetLowerBound(2);

            T[, ,] result = (T[, , ])(Array.CreateInstance(typeof(T), new int[] { newLengthA, newLengthB, newLengthC }, new int[] { lowerSA, lowerSB, lowerSC }));
            int lengthSA = upperSA + 1 - lowerSA,
                lengthSB = upperSB + 1 - lowerSB,
                lengthSC = upperSC + 1 - lowerSC;
            int copyMaxA = Math.Min(newLengthA, lengthSA),
                copyMaxB = Math.Min(newLengthB, lengthSB),
                copyMaxC = Math.Min(newLengthC, lengthSC);

            source.CubicCopy(result, copyMaxA, copyMaxB, copyMaxC);
            return(result);
        }