-3

I'm kind of lost here as I do not know how to proceed. Here's what I got so far:

//T[] tab initialised earlier with T elements)

public bool Delete(T element)
            {
                var find = Array.FindIndex(tab, x => x.CompareTo(element) == 0); 
                if (find == -1) // if item not found then don't do anything
                {
                    return false;
                }
                else
                {
                    tab.Remove(element); // can't use Remove with
                        return true;
                }

            }

Given Error:

Error 1 'System.Array' does not contain a definition for 'Remove' and no extension method 'Remove' accepting a first argument of type 'System.Array' could be found

General Grievance
  • 4,555
  • 31
  • 31
  • 45
sourpet
  • 17
  • 8
  • 3
    since I can't use Remove with T[] Arrays. Why? – Nikhil Agrawal Mar 24 '13 at 17:21
  • An array has a fixed length, and you can't actually remove from it. One thing you can do is overwrite the existing element with "nothing". But that will leave a "hole" in the array. Like this: `tab[find] = default(T);` Depending on what `T` is you can also use `null` or `new T()`. – Jeppe Stig Nielsen Mar 24 '13 at 17:48

1 Answers1

4

Yes, you cannot remove element out of tab because tab is declared as array [] which does not support Remove method, if possible, declare tab as List<T>, so you are able to call Remove from List<T>

cuongle
  • 74,024
  • 28
  • 151
  • 206