any one know how to search a string array for a particular value a then remove it from there without keeping a null element to find the element where the value exists and then to remove the element

Please if any one know how to do it give me an example

lets say there is a string array that have 3 values

p001
p002
p005

i want the value p002 to be removed from the array
but i want to do this at the run time so i don't know the which value is in which element so i need a way when i give the value p002 it should be searched in the array and if it exists it should removed from the array

ArrayList arrayList=new ArrayList();
//following code can be used to add items  to array
 arrayList.Add("poo1");
void RemoveString( object pobj)//you can change parameter type 
{
   arrayList.Remove(pobj);
}

Edited 6 Years Ago by __avd: Added [code] tags.

Comments
not a bad example

It is better to use the generic List type:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            List<string> MyList = new List<string>();
            MyList.Add("p001");
            MyList.Add("p002");
            MyList.Add("p003");
            for (int i = 0; i < MyList.Count; i++)
            {
                Console.WriteLine(MyList[i]);
            }
            MyList.Remove("p002");
            Console.WriteLine("#################### After removing:");
            for (int i = 0; i < MyList.Count; i++)
            {
                Console.WriteLine(MyList[i]);
            }
            Console.ReadKey();
        }
    }
}
Comments
Generics++
Good example!

It is better to use the generic List type:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            List<string> MyList = new List<string>();
            MyList.Add("p001");
            MyList.Add("p002");
            MyList.Add("p003");
            for (int i = 0; i < MyList.Count; i++)
            {
                Console.WriteLine(MyList[i]);
            }
            MyList.Remove("p002");
            Console.WriteLine("#################### After removing:");
            for (int i = 0; i < MyList.Count; i++)
            {
                Console.WriteLine(MyList[i]);
            }
            Console.ReadKey();
        }
    }
}

Also known as a "Collection" and darn you for getting up earlier than me and mentioning it first :P

But yes, your best bet is what ddanbe said as it dynamically increases it's size as items are added to it and can have items removed from it, reducing it's size dynamically, without having to insert null values as placeholders to overwrite them.

Don't forget to mark the thread solved once your issue is resolved :)

Comments
You got to live in Belgium ! :)
This question has already been answered. Start a new discussion instead.