Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Refference Array Inside Array (C)

Discussion in 'Scripting' started by Faestus, Jul 26, 2014.

  1. Faestus

    Faestus

    Joined:
    Jul 23, 2014
    Posts:
    68
    So I have this array:

    int[][] Array= new int[][] {
    new int[] {1,2},
    new int[] {2,2},
    new int[] {2,1}
    }

    If I try sizeof(Array) it works, but sizeof(Array[0]) does not. Why?
     
  2. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
  3. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
    And I'd suggest using a int[,] Array instead of an int[][], assuming each rank is the same length

    Then you get the length with myArray.GetLength(int dimension)
     
  4. Faestus

    Faestus

    Joined:
    Jul 23, 2014
    Posts:
    68
  5. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
    Personal preferrence, on syntax niceness.
    But read this and judge for yourself
    http://www.dotnetperls.com/jagged-2d-array-memory

    int[x][y][z] can be int[x,y,z]