Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Declaring and using jagged array (Array of Arrays) in C#

You can declare and use jagged array like below,
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace ForgetCode
  7. {
  8. public class MainClass
  9. {
  10. public static void Main()
  11. {
  12. //General declaration
  13. int[][] numbers = new int[2][] { new int[] { 2, 3, 4 }, new int[] { 5, 6, 7, 8, 9 } };
  14.  
  15. //Omitting the size
  16. int[][] numbers2 = new int[][] { new int[] { 2, 3, 4 }, new int[] { 5, 6, 7, 8, 9 } };
  17.  
  18. // Direct usage of new inside the array
  19. int[][] numbers3 = { new int[] { 2, 3, 4 }, new int[] { 5, 6, 7, 8, 9 } };
  20. }
  21. }
  22. }