tmighty
tmighty

Reputation: 11389

Enum to int casting for array index

I am confused what I should do to make this work:

enum Phonemes { Phoneme0 = 0, Phoneme1 = 1, Phoneme2 = 2 };
enum Features { PhonemeID = 0, IsFirst = 1, IsLast = 2 };

        int[][] inputs = new int[3][];
        inputs[0] = new int[3];
        inputs[1] = new int[3];
        inputs[2] = new int[3];

        inputs[(int)Phonemes.Phoneme0][int()Features.PhonemeID] = 1;

The first enum to int works fine, but as soon as I add the [int()Features.PhonemeID], the compiler does not like it anymore.

Can somebody help?

Upvotes: 0

Views: 111

Answers (2)

Øyvind Bråthen
Øyvind Bråthen

Reputation: 60694

I think this is a simple typo

Change it to this:

inputs[(int)Phonemes.Phoneme0][(int)Features.PhonemeID] = 1;

You have written int() instead of (int)

Upvotes: 0

gzaxx
gzaxx

Reputation: 17590

Change it to:

 inputs[(int)Phonemes.Phoneme0][(int)Features.PhonemeID] = 1;

your brackets were wrong :)

Upvotes: 2

Related Questions