Advertisement
Danvil

Изменить размер массива

Feb 21st, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.21 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Изменить_размер_массива
  8. {
  9.     class Program
  10.     {
  11.         static void ShowArray(int[,] arrNums)
  12.         {
  13.             for (int intC = 0; intC < arrNums.GetLength(0); intC++)
  14.             {
  15.                 for (int intB = 0; intB <arrNums.GetLength(1); intB++)
  16.                     Console.Write(arrNums[intC, intB] + " ");
  17.                 Console.WriteLine();
  18.             }
  19.         }
  20.         static int[,] ResizeArray(int[,] arrNums, int[] arrSizes)
  21.         {
  22.             int[,] arrTemp = new int[arrSizes[0], arrSizes[1]];
  23.             for (int intC = 0; intC < (Math.Min(arrNums.GetLength(0), arrSizes[0])); intC++)
  24.                 for (int intB = 0; intB < (Math.Min(arrNums.GetLength(1), arrSizes[1])); intB++)
  25.                     arrTemp[intC, intB] = arrNums[intC, intB];
  26.             return arrTemp;
  27.         }
  28.         static void Main(string[] args)
  29.         {
  30.             int[,] arrZ = { { 1, 2, 3, 4, 5, 6 }, { 7, 8, 9, 10, 11, 12 } };
  31.             arrZ = ResizeArray(arrZ, new int[] { 4, 3});
  32.             ShowArray(arrZ);        
  33.             }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement