Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Threading;
- namespace Delegates
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[][] data =
- {
- new string[]{"C1R1", "C1R2", "C1R3"},
- new string[]{"C2R1", "C2R2", "C2R3", "C2R4" },
- new string[]{"C3R1", "C3R2", },
- };
- DrawTable(data);
- Console.WriteLine("________________________");
- Console.WriteLine(GetCell(data, 0, 0)); //C1R1
- Console.WriteLine(GetCell(data, 1, 2)); //C3R2
- Console.WriteLine(GetCell(data, 2, 2)); //Empty
- }
- static string GetCell(string[][] data, int column, int raw)
- {
- string ansv;
- if (column > data.Length - 1 || raw > data[column].Length - 1)
- {
- ansv = "Empty";
- }
- else ansv = ansv = data[column][raw];
- return ansv;
- }
- static void DrawTable(string[][] data)
- {
- var max = 0;
- for (var i = 0; i < data.Length; i++)
- {
- if (max < data[i].Length) max = data[i].Length;
- }
- Console.WriteLine("Column 1 | Column 2 | Column 3 |");
- for (var j = 0; j < max; ++j)
- {
- for (var i = 0; i < data.Length; ++i)
- {
- try
- {
- Console.Write(data[i][j] + " | ");
- }
- catch
- {
- Console.Write("empty | ");
- }
- }
- Console.WriteLine();
- }
- }
- /*
- Column 1 | Column 2 | Column 3
- C1R1 | C2R1 | C3R1
- C1R2 | C2R2 | C3R2
- C1R3 | C2R3 | Empty
- Empty | C2R4 | Empty
- */
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement