-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

2
  • 3
    since I can't use Remove with T[] Arrays. Why? Commented Mar 24, 2013 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(). Commented Mar 24, 2013 at 17:48

1 Answer 1

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>

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.