删除double []数组中的零 [英] remove zeros in a double[] array

查看:88
本文介绍了删除double []数组中的零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何删除数组中的零?
例如,如果您有array[] numbers = new array[2000]
数组中有值,但有些为零.我想删除零并返回另一个array []

How do you remove zeros that are in an array?
For instance if you have array[] numbers = new array[2000]
There are values in the array but some are zero. I would like to remove the zeros and return another array[]

推荐答案

在这里是:

Here it is :

public double[] RemoveZeros(double[] source)
{
    return source.Where(i => i != 0).ToArray();
}



希望对您有所帮助.



Hope it helps.


dim a as integer=0
dim str as string
while a<array.length>
str=array[a]
if str=0 then 
array.delete(a)
end if
a=a+1
end while</array.length>




试试看,不要循环.
Hi,

Try this without a loop.
int[] a = { 1, 2, 3, 0, 7, 0 };
a = a.Where(T => T != 0).ToArray();


这篇关于删除double []数组中的零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆