如何从字符串数组中删除项目 [英] How Can I Remove Items From A String Array
本文介绍了如何从字符串数组中删除项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个字符串数组,如字符串[] nums = {1,2,3 ............,34}
我需要10个元素来自每次都是数组,直到长度超过。如何使用c#
I am having a string array like string[] nums={1,2,3............,34}
I need 10 elements from that array each time until the length exceeds.How can i do that using c#
推荐答案
数组不是为添加或删除元素而设计的。所有方法都改变了数组的大小( https://msdn.microsoft.com /en-us/library/bb348051(v=vs.110).aspx [ ^ ])实际上不修改数组对象;他们创建一个新的,用旧数组中的数据填充它并返回一个新的数组对象,而不是与原始数据相同。
对于此类操作,您需要使用集合,最接近数组System.Collections.Generic.Array<& ft;
:
https://msdn.microsoft .com / zh-CN / library / 6sh2ey19%28v = vs.110%29.aspx [ ^ ]。
你总是可以从列表实例: https://msdn.microsoft.com/en-us /library/x303t819(v=vs.110).aspx [ ^ ]。
-SA
Arrays are not designed for adding or removing elements. All methods changing the size of array (https://msdn.microsoft.com/en-us/library/bb348051(v=vs.110).aspx[^]) don't actually modify an array object; they create a new, populate it with the data from old array and return a new array object, not referentially identical to the original one.
For such operations, you need to use collections, with the closest to the array beingSystem.Collections.Generic.Array<&ft;
:
https://msdn.microsoft.com/en-us/library/6sh2ey19%28v=vs.110%29.aspx[^].
You can always make an array from a list instance: https://msdn.microsoft.com/en-us/library/x303t819(v=vs.110).aspx[^].
—SA
这篇关于如何从字符串数组中删除项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文