Assign values to a 2 dimension Arrays

Hello. I can’t find the way to do this, can someone help?

I simplify the problem to get the anwer (i actually have so many of these double arrays):

I have a double array:

int [ , ] = theArray;

theArray[ , ]= new int[5, 2];

In my head, there should be 3 different ways to declare its values. FRom best way (in my head) to worst way to do it, are they possible?


BEST WAY:
So there are 5 arrays of 2 integrer numbers.

There is a way to define its values array per array? something like this:

theArray[0] = [3,4];
theArray[1] = [5,8];
theArray[2] = [1,1];
theArray[3] = [7,0];
theArray[4] = [3,0];

2nd BEST WAY:

theArray = [[3,4],[5,6],[1,1,],[7,0],[3,0]];

WORST WAY:

Because, defining all values 1 by 1 will be sooo long:

theArray[0,0] =3;
theArray[0,1] =4;
theArray[1,0] =5;
theArray[1,1] =8;
......

Anyone knows how to do best way? and if not, how to do 2nd best way?

THAANKS !!! :smiley:

How about this, assuming you know your values in advance:

void Awake()
{
    int[,] array = new int[5, 6]
    {
        {00, 01, 02, 03, 04, 05},
        {10, 11, 12, 13, 14, 15},
        {20, 21, 22, 23, 24, 25},
        {30, 31, 32, 33, 34, 35},
        {40, 41, 42, 43, 44, 45}
    };

    print(array[2,4]);
}

Greetings, @tormentoarmagedoom. I’m not convinced that you want a 2-dimensional array. You want a 1-dimensional array of pairs. This is what structs are for but you can do it without structs, using an array of Vector2. For example:

using UnityEngine;

public class Array : MonoBehaviour
{
    private void Start()
    {
        Vector2[] pairs = new Vector2[10];
        pairs[0] = new(0, 100);
        pairs[1] = new(1, 101);

        print(pairs[0]);
        print(pairs[1].y);
    }
}

As you can see you can then address a pair of values or individual elements. Unless you are certain that your arrays will never grow, you might also want to consider using a List.