C#中移动数组最快的方法 [英] C# quickest way to shift array
本文介绍了C#中移动数组最快的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何快速在数组中一个班的所有项目的左侧,用null填充结束了吗?
How can I quickly shift all the items in an array one to the left, padding the end with null?
例如,[0,1,2,3,4,5,6]将成为[1,2,3,4,5,6,空]
For example, [0,1,2,3,4,5,6] would become [1,2,3,4,5,6,null]
编辑:我连忙说,但我想我的意思有效。我需要这样做,而无需创建一个列表或其他一些数据结构。这是我需要做几十万次的时间尽可能短量。
I said quickly but I guess I meant efficiently. I need to do this without creating a List or some other data structure. This is something I need to do several hundred thousand times in as short amount of time as possible.
推荐答案
只是做:
int?[] newAr = new int?[oldAr.Length];
for (int i = 1; i < oldAr.Length; i++)
newAr[i - 1] = oldAr[i];
这篇关于C#中移动数组最快的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文