从Two Dimensional String Array中删除Null值 [英] Remove Null values from Two Dimensional String Array

查看:82
本文介绍了从Two Dimensional String Array中删除Null值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



i想要从二维字符串数组中删除所有Null值条目。我该怎么做?



string [,] strArray =新字符串[1000,1000];



i仅使用500.其他条目为null。当我循环它时,它会运行所有1000 entries.i想要停止它。如何?



如果是单维数组我们可以像这样使用linq。

Arr_Formual = Arr_Formual.Where(s =>!String.IsNullOrEmpty(s))。ToArray();

但对于二维数组如何使用linq?

Hi,
i want to Remove all Null value entries from the Two Dimensional String Array .How can i do that?

string[,] strArray = new string[1000,1000];

i have used only 500. others entries are null.when i loop it,it runs thro all the 1000 entries.i want to stop it.how?

if it is a single dimensional array they we can use linq like this.
Arr_Formual = Arr_Formual.Where(s => !String.IsNullOrEmpty(s)).ToArray();
but for two dimensional array how to so with linq?

推荐答案

1>全局声明一个计数器varibale

2>然后当您向数组添加值时,计数器变量

3>最后添加到数组完成然后在任何for循环之外添加此行



1> declare one counter varibale globally
2> then when you add values to the array increament the counter varibale
3> and at last after all the adding to the array is finish then outside of any for loop add this line

Array.Resize(ref strArray , counter);


您可以查找可用的 C#中的稀疏矩阵实现 [ ^ ]。
You may look for an available sparse matrix implementation in C#[^].


If你确定在你使用的那些中没有空值。

然后你可以使用while语句在循环时打破循环

命中第一个空值。

通过这种方式,您不必删除任何条目,并且

循环不会遍历所有1000个条目。
If you are sure there are no null values in the ones you used.
Then you can use a while statement to break the loop when that loop
hits the first null value.
In that way you don't have to delete any entries and the
loop doesn't run through all 1000 entries.


这篇关于从Two Dimensional String Array中删除Null值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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