使用C#删除数组中的空白值 [英] Remove blank values in the array using c#

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

问题描述

是否有任何方法可以从数组
中删除空白索引,例如

Is there any method which remove blank indexs from the array e.g

string[] test={"1","","2","","3"};

在这种情况下,是否有任何方法可以使用c#
从数组中删除空白索引最后,我想以这种格式获取数组
test = { 1, 2, 3}; 意味着要从中删除两个索引数组,最后我得到3个索引
我没有为数组写确切的代码,这是我想做的提示

in this case is there any metod available to remove blank index from the array using c# at the end i want to get array in this format test={"1","2","3"}; which mean two index remove from the array and finaly i got 3 index I'am not wriing exact code for array this is hint which i want to do

推荐答案

如果您使用的是.NET 3.5+,则可以使用linq。

If you are using .NET 3.5+ you could use linq.

test = test.Where(x =>!string .IsNullOrEmpty(x))。ToArray();

这篇关于使用C#删除数组中的空白值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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