假设我有这个多维数组:
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[]
where Vector2
是一个公共类,它只包含x
and y
特性:
public class Vector2 {
public float x;
public float y;
public Vector2(float x, float y) { this.x = x; this.y = y }
}
所以我想从 Array[2] 元素构造 Vector2 元素,这些元素是上面的子数组vertices
数组变量。
我这样做:
Array.ConvertAll(vertices[0],
new Converter<float[], Vector2>(verticesSequence => { return new Vector2(verticesSequence[0], verticesSequence[1]); }));
但是,作为回报,我收到此错误消息:
错误 15 最佳重载方法匹配
'System.Array.ConvertAll(浮点[][],
System.Converter)' 有一些无效
论点