Pergunta

I've been looking at different answers and stuff (like jagged array) but I still cant understand how this would work (or if it even works). In the end, this should be which my arduino uses for writing> But that aside. Here's my problem:

I want to make an multidimensional array which represents all the letters from the alphabet. Each index has two arrays; one for directions and one for rotations. Something like this:

  |      0       |      1      |
0 | directions[] | rotations[] |
1 | directions[] | rotations[] |
................................
25| directions[] | rotations[] |

How would one accomplish this? Is it even accomplishable? For now I'm using this in C#, but I have to convert it to C eventually. Any help or insight is greatly appreciated. Thanks in advance!

EDIT: New code with LetterData class and example values

public class LetterData
    {
        public int[] distance;
        public int[] rotation;
    }

    public LetterData[] sequence = new LetterData[25];

    void Start () 
    {

        for (int i = 0; i < 25; i++)
        {
            sequence[i].distance = new int[2];
            sequence[i].rotation = new int[2];
        }
}
Foi útil?

Solução

How about simplifying?:

public class LetterData
{
    public DirectionsType[] Directions;
    public RotationsType[] Rotations;
}

LetterData[] myVar = new LetterData[25];
...
myVar[i].Directions = new DirectionsType[n];
...
myVar[i].Directions[k] = value;

Answer for EDIT:

public class LetterData
    {
        public int[] distance;
        public int[] rotation;
    }

public class MyClass
{
    public LetterData[] sequence = new LetterData[25];

    void Start () 
    {
        for (int i = 0; i < 25; i++)
        {
            sequence[i] = new LetterData();
            sequence[i].distance = new int[2];
            sequence[i].rotation = new int[2];
        }
    }
}

...

MyClass m = new MyClass();
m.Start();
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top