本文介绍了从数组中删除值并重新绑定它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,我正在制作一个asp Web应用程序 我有一个数组"bm",该数组中有三个值
hello to all i am making an asp web application I have an array "bm" in this array there are three values
index 0-ram index 1-shyam index 2-sita现在,在另一个名为"xz"的数组中,我正在检索类似的索引
Now in another array named as "xz" i am retrieving indexes like
Index 0-----value is 0 index 1---- values is 2现在我想从数组bm中删除索引0和索引1,并再次像这样bm [0] = sita 重新绑定数组bm plz help
now i wants to remove index 0 and index 1 from array bm and rebinds the array bm again like this bm[0]= sita plz help
推荐答案没有看到您的代码,就不可能完全准确.例如,如果要调用方法来执行此操作,则必须将数组引用作为参考值传递,否则对"bm"进行的任何更改,而不是"bm"数组的内容都不会离开该方法. > 从对"bm [0]"的引用中,我假设您正在使用C#. C#无法从数组中删除元素:您所要做的就是声明另一个数组,然后将所需的元素复制到其中,并忽略不包含的元素.我将使用List而不是数组,因为您无需事先知道将需要多少个元素: Without seeing your code, it is impossible to be totally accurate. For example, if you are calling a method to do this, then the array reference must be passed as a reference value or any change to "bm" rather than the content of the "bm" array will not leave the method. I assume from the reference to "bm[0]" that you are using C#. C# cannot remove elements from an array: all you can do is declare another array and copy the elements you want into it, and omit the ones you don''t. I would use a List rather than an array, as you don''t need to know in advance how many elements you will need: List<string> keepThese = new List<string>(); foreach (string s in bm) { if (IsToBeKept(s)) { keepThese.Add(s); } } bm = keepThese.ToArray();
更多推荐
从数组中删除值并重新绑定它
发布评论