我想制作一个Instruction
数组,一个需要int
和两个Vector3
的对象。我知道如何制作数组,但是如果可能的话,我不确定如何创建多元素对象的数组。即。
int[] myInts = new int[] {1, 4, 1, 5}; //Creates an array of ints
BUT
Instruction[] instructions = new Instruction[] {
{1, new Vector3(1, 5, 2), new Vector3(4, 1, 7)}
{2, new Vector3(6, 2, 7), new Vector3(9, 7, 4)}
}
你是这样做的,还是不同的?
答案 0 :(得分:3)
您必须指定new
关键字并输入:
Instruction[] instructions = new Instruction[] {
new Instruction {1, new Vector3(1, 5, 2), new Vector3(4, 1, 7)}, //And add comma
new Instruction {2, new Vector3(6, 2, 7), new Vector3(9, 7, 4)}
};