0

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];
        }
}
0

1 Answer 1

2

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();
Sign up to request clarification or add additional context in comments.

9 Comments

This makes so much sense. How I missed this I'll never know.
Mark it as answer, and all shall be forgiven (until next booboo)!! :)
Thanks for your answer mate. This kiss made my booboo go away.
I just updated the answer with one possible solution... other variants of course is to have List instead of array and thus you can just .Add to make easier, or improve LetterData class to make those setters and getters that guarantee that array or list is already instantiated (if size is known in case of the array).
Here you go, you were missing sequence[i] = new LetterData();
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.