OldBeliver

Show 2D array

May 10th, 2022 (edited)
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.14 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _2DArray
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             Array array = new Array();
  10.             array.ShowInfo();
  11.         }
  12.     }
  13.  
  14.     class Array
  15.     {
  16.         int[,] numbers = new int[,]  { { 1, 2, 3}, {4, 5, 6 } };
  17.  
  18.         public void ShowInfo()
  19.         {
  20.             // ПЛОХОЙ КОД ИЗ-ЗА ДВОЙНОЙ ВЛОЖЕННОСТИ FOR
  21.             //for (int i = 0; i < numbers.GetLength(0); i++)
  22.             //{
  23.             //    for (int j = 0; j < numbers.GetLength(1); j++)
  24.             //    {
  25.             //        Console.Write($"{numbers[i,j]} ");
  26.             //    }
  27.             //}
  28.  
  29.             ShowArray();
  30.         }
  31.  
  32.         private void ShowArray()
  33.         {
  34.             for (int i = 0; i < numbers.GetLength(0); i++)
  35.             {
  36.                 ShowLine(i);
  37.                 Console.WriteLine();
  38.             }
  39.         }
  40.  
  41.         private void ShowLine(int line)
  42.         {
  43.             for (int i = 0; i < numbers.GetLength(1); i++)
  44.             {
  45.                 Console.Write($"{numbers[line,i]} ");
  46.             }
  47.         }
  48.     }
  49. }
  50.  
Add Comment
Please, Sign In to add comment