开发者

how to loop through an array of vectors in C#

开发者 https://www.devze.com 2022-12-31 20:46 出处:网络
I now have an array of vectors: static Vector3[] axes = new Vector3[] { Vector3.Uni开发者_高级运维tX, Vector3.UnitY, Vector3.UnitZ };

I now have an array of vectors:

static Vector3[] axes = 
    new Vector3[] { Vector3.Uni开发者_高级运维tX, Vector3.UnitY, Vector3.UnitZ };

and I want to loop through it,the code I write is:

for(int i=0;i<axes.Length;i++)
 {

    do sth. about axes[i];

 }

However,it doesnt work and gets into infinite loop,could anyone help? thx.


It might be that you are adding a Vector3 to the array in the for loop.

Edit: Even though arrays are fixed size you could have code similar to this in the loop giving the add effect:

for(int i=0;i<axes.Length;i++)
{
    axes = axes.Concat(new Vector3[] { new Vector3() }).ToArray();
}

This will cause the length to increase each time and the loop to go into an infinite loop (more specific to loop until an integer overflow occurs.

0

精彩评论

暂无评论...
验证码 换一张
取 消