Click here to Skip to main content
15,877,915 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

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?
Updated 13-Jun-13 19:05pm
vinayakJJ 14-Jun-13 1:49am    
see my answer

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);
Share this answer
You may look for an available sparse matrix implementation in C#[^].
Share this answer
John Sathish Tamilarasu 13-Jun-13 8:45am    
The size of the array is just i want to delete all the null valued entries.any possibilities?
CPallini 13-Jun-13 11:02am    
Nope. You might use another data structure, for instance a a std::map.
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.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900