Join the Stack Overflow Community
Stack Overflow is a community of 6.5 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

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];
        }
}
share|improve this question
    
Integers my good man – Amacoder Mar 10 '14 at 20:16
up vote 2 down vote accepted

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();
share|improve this answer
    
This makes so much sense. How I missed this I'll never know. – Amacoder Mar 10 '14 at 19:24
2  
Mark it as answer, and all shall be forgiven (until next booboo)!! :) – LB2 Mar 10 '14 at 19:26
    
Thanks for your answer mate. This kiss made my booboo go away. – Amacoder Mar 10 '14 at 20:20
1  
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). – LB2 Mar 10 '14 at 20:27
1  
Here you go, you were missing sequence[i] = new LetterData(); – LB2 Mar 10 '14 at 21:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.