Advertisement
VitalyD

Untitled

May 13th, 2018
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.02 KB | None | 0 0
  1. using System;
  2. using System.Threading;
  3.  
  4. namespace Delegates
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string[][] data =
  11.             {
  12.                 new string[]{"C1R1", "C1R2", "C1R3"},
  13.                 new string[]{"C2R1", "C2R2", "C2R3", "C2R4" },
  14.                 new string[]{"C3R1", "C3R2", },
  15.             };
  16.  
  17.            
  18.             DrawTable(data);
  19.  
  20.  
  21.             Console.WriteLine("________________________");
  22.  
  23.             Console.WriteLine(GetCell(data, 0, 0)); //C1R1
  24.             Console.WriteLine(GetCell(data, 1, 2)); //C3R2
  25.             Console.WriteLine(GetCell(data, 2, 2)); //Empty
  26.         }
  27.  
  28.         static string GetCell(string[][] data, int column, int raw)
  29.         {
  30.  
  31.             string ansv;
  32.             if (column > data.Length - 1 || raw > data[column].Length - 1)
  33.             {
  34.                 ansv = "Empty";
  35.             }
  36.             else ansv = ansv = data[column][raw];
  37.  
  38.             return ansv;
  39.         }
  40.  
  41.  
  42.         static void DrawTable(string[][] data)
  43.         {
  44.  
  45.             var max = 0;
  46.             for (var i = 0; i < data.Length; i++)
  47.             {
  48.                 if (max < data[i].Length) max = data[i].Length;
  49.             }
  50.  
  51.  
  52.  
  53.             Console.WriteLine("Column 1 | Column 2 | Column 3 |");
  54.             for (var j = 0; j < max; ++j)
  55.             {
  56.                 for (var i = 0; i < data.Length; ++i)
  57.                 {
  58.                     try
  59.                     {
  60.                         Console.Write(data[i][j] + "     | ");
  61.                     }
  62.                     catch
  63.                     {
  64.                         Console.Write("empty    | ");
  65.                     }
  66.                 }
  67.                 Console.WriteLine();
  68.             }
  69.  
  70.  
  71.  
  72.         }
  73.  
  74.         /*
  75.             Column 1 | Column 2 | Column 3
  76.             C1R1     | C2R1     | C3R1
  77.             C1R2     | C2R2     | C3R2
  78.             C1R3     | C2R3     | Empty
  79.             Empty    | C2R4     | Empty                
  80.          */
  81.     }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement