How to remove item from 1 d array

  • Thread starter Thread starter Jeff User
  • Start date Start date
J

Jeff User

Hi
..net 1.1
I have a simple string array like
string[] myArray = CallToWebServiceThat_Returns_Elements;

I want to remove an item from the array and also remove its position.
I can search the array and find the index of desired string, but how
can I remove?

Do I have to somehow create a new array that is smaller and then copy
everything over except the value that I want?
Is there some utility to do this?

Thanks
jeff
 
Jeff User said:
.net 1.1
I have a simple string array like
string[] myArray = CallToWebServiceThat_Returns_Elements;

I want to remove an item from the array and also remove its position.
I can search the array and find the index of desired string, but how
can I remove?

You can't. Arrays are fixed size.
Do I have to somehow create a new array that is smaller and then copy
everything over except the value that I want?
Is there some utility to do this?

An easier way of working is to use ArrayList or List<string> if you're
using .NET 2.0.

However, Array.Copy helps you with the array copying part. You could
write helper methods to deal with the rest if you need to do it often.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top