Searching ArrayList [C# WindowForms]

  • Thread starter Thread starter MikeY
  • Start date Start date
M

MikeY

Hi Everyone,

I'm am trying to find the best method option for searching through an
ArrayList and getting various items at a time. It could be 0 to 14, 15 to 25
etc,etc. I wish .GetRange(0,45) would give more options than just zero base
to whatever.

Right now, (unless there is a better option) I will keep calling the
ArrayList at various times getting the 15 or less items at a time and put
the items into another ArrayList for my usage. Is looping the best method?
Any and all help is appreciated. A sample code is at follows


private void Get_ArrayList()
{
ArrayList_Load_Data myArrayList_Load_Data = new ArrayList_Load_Data();
myArrayList = myArrayList_Load_Data.Test;
ArrayList myArrayList2 = new ArrayList();

foreach(DataItem myItem in myArrayList)
{
if(myItem.Index >= 0 && myItem.Index < 14)
{
myArrayList2.Add(myItem);
}
}
foreach(DataItem myItem1 in myArrayList2)
{
MessageBox.Show(": " + myItem1.Name + myItem1.Index);
}
}.
 
if its not broken, then dont fix it :)

there is probably a dozen different ways to accomplish this. You could
override .GetRange and write your own code for getting the range, or
simply loop like you are doing here.
 
Txs DKode,

I was just looking to see if there was a better way of getting at my data or
getting at a group of my items. I just wish GetRange would get my data items
at various point GetRange(22,26) instead of GetRange(0,26) when I really
only need the last 5 items. Txs Again

MikeY
 
Txs Again DKode,

After doing the sample at MSDN I summised that I was using the GetRange
wrong. Anyhow I am going to with your origional reply "If it ain't broke"
reply, because I would still need to know where and the amount of data
before using this method other wise I'll just end up getting the dreaded
offset length out of bound exception. Txs Again DKode.

MikeY
 
Back
Top