Rajesh45
Rajesh45

Reputation: 43

Remove value from array?

How can I take out one line of this array

  array< array< int^ >^ >^ sample = gcnew array< array< int^ >^ >{
        gcnew array<int>{0, 0, 0, 0, 0},
        gcnew array<int>{1, 1, 1, 1, 1},
        gcnew array<int>{2, 2, 2, 2, 2},
    };

So it would be :-

  array< array< int^ >^ >^ sample = gcnew array< array< int^ >^ >{
        gcnew array<int>{0, 0, 0, 0, 0},
        gcnew array<int>{2, 2, 2, 2, 2},
    };

Rajesh.

Upvotes: 0

Views: 2855

Answers (2)

Chris Schmich
Chris Schmich

Reputation: 29496

While you can use Array::Resize to resize your array and use the shift method bachchan mentions, you generally don't add or remove items from a C++/CLI array.

If you need add or remove items dynamically from a collection, look into using the System::Collections::Generic::List<T> type (see MSDN).

Depending on what you're doing with the collection, you can use even more sophisticated structures, e.g. HashSet<T> or Dictionary<K, V>.

Upvotes: 1

bachchan
bachchan

Reputation: 313

for ( i = 0; i < n; i++ ) { if ( a[i] == target ) break; }

while ( ++i < n ) a[i - 1] = a[i]; --n;

The actual process doesn't include a delete step, it's just the shift step:

Upvotes: 0

Related Questions