假設我有這樣的多維數組:轉換多維數組的元素,以不同類型的
float[][,] vertices = {
new float[,]{ {0f, 1.28f}, {1.28f, 2.56f}, {3.84f, 2.56f}, {5.12f, 1.28f}, {3.84f, 0f}, {1.28f, 0f}, {0f, 1.28f} },
new float[,]{ {0f, 3.83f}, {1.27f, 5.12f}, {3.87f, 5.12f}, {5.12f, 3.83f}, {5.12f, 1.26f}, {3.87f, 0f}, {1.27f, 0f}, {0f, 1.26f}, {0f, 3.83f} }
};
現在,我想給各子陣列轉換爲Vector2[]
類型的數組,其中Vector2
是一個公共類,它只是包含x
和y
屬性:
public class Vector2 {
public float x;
public float y;
public Vector2(float x, float y) { this.x = x; this.y = y }
}
所以我想從陣列構造Vector2元素[2]的元素,這是在上述vertices
數組變量的子陣列。
餘像這樣做:
Array.ConvertAll(vertices[0],
new Converter<float[], Vector2>(verticesSequence => { return new Vector2(verticesSequence[0], verticesSequence[1]); }));
然而,在返回我收到此錯誤消息:
錯誤15最好重載方法匹配 「System.Array.ConvertAll(浮[] [], System.Converter)」有一些無效 參數
什麼是invalild參數? – Sayse 2014-09-04 06:27:28
我不知道。這就是爲什麼我問我的問題。我不知道我的語法有什麼問題。 – GuardianX 2014-09-04 06:34:04
對不起,我以爲可能有更多的信息在錯誤信息(我會看看如果我可以解決它) – Sayse 2014-09-04 06:34:40