我有一个包含对象数组的静态类。
public static Waypoint[] AtoB
{
get
{
return new Waypoint[] {
new Waypoint(49.251f,-851.837f),
new Waypoint(66.7397f,-843.165f),
new Waypoint(77.8777f,-825.462f)
};
}
}
现在我想要创建另一个Waypoint数组,名为BtoA,它与AtoB相同,但顺序相反。因此,大致如下:
public static Waypoint[] BtoA
{
get { return AtoB.Reverse(); }
}
这个可以吗?
Obj[].Reverse().ToArray()
和Array.Reverse(Obj[])
之间的区别吗? - user2914191public static readonly Waypoint[] AtoB = new [] { new Waypoint(49.251f,-851.837f), new Waypoint(66.7397f,-843.165f), new Waypoint(77.8777f,-825.462f) };
这样您就可以重复使用同一个数组,而不是每次都创建新的数组,但在这种情况下,应该选择选项#1来反转它。 - Sergey Berezovskiy