0

I have a 2D array object fixed Size

object[,] = new object[1,50];

But Some times some sections of this null which i don't want in my Operation. I wanted to Remove Nulls from 2D Array.

Where I couldn't find Remove Function with this. I don't want any loop to check each index.

How to do this.

Thanks in Advance.

Jankya
  • 966
  • 2
  • 12
  • 34
  • You did't use any identifier for the array. – Meysam Tolouee May 20 '14 at 09:04
  • 1. Im not sure how you can have a 0 column 2d array and 2. every element will be null since you havent initialized anything. 3. @MeysamTolouee - they [*are* the same thing](http://stackoverflow.com/q/3070628/1324033) – Sayse May 20 '14 at 09:04

1 Answers1

3

An array is fixed size; you cannot "remove" anything. You can replace values with other values, via the indexer - but frankly I would say that null is the classic "doesn't have a value" for something we only know as object.

So you have a few options:

  • if the problem is borders: create the array with the correct size so that there are no borders
  • or initialize all the values to non-null values at the start
  • or loop over the cells and replace null values with non-values at your convenience
Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900