Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.43 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 DimensionTest
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string[][][] test = {
  14.                 new string[][] {
  15.                     new string[] { "AA", "AB" }, new string[] { "BA", "BB" }
  16.                 },
  17.                 new string[][] {
  18.                     new string[] { "CA", "CB" }, new string[] { "DA", "DB"  }
  19.                 }
  20.             };
  21.             string[,] test2 = { { "A" }, { "B" }, { "C" }, { "D" } };
  22.             IterateArray(test, "test");
  23.             IterateArray(test2, "test2");
  24.             Console.ReadLine();
  25.         }
  26.  
  27.         static void IterateArray(Array arr, string name)
  28.         {
  29.             Console.WriteLine("Iterating \"" + name + "\"");
  30.             if (arr.Rank == 1)
  31.                 IterateMono(arr);
  32.             else
  33.                 IterateMulti(arr);
  34.         }
  35.  
  36.         static void IterateMono(Array arr)
  37.         {
  38.             if (arr is string[])
  39.                 foreach (string s in arr)
  40.                     Console.WriteLine(s);
  41.             else
  42.                 foreach (Array sub in arr)
  43.                     IterateMono(sub);
  44.         }
  45.  
  46.         static void IterateMulti(Array arr)
  47.         {
  48.             foreach (string s in arr)
  49.                 Console.WriteLine(s);
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement