Question

I have problem with this. I have one arrayList, and I want to copy some objects to another. More important, each object has a specific property, which I'm using it as filter to copy. Unfortunately, I have to work with .NET 1.1, so I can't use lamda expressions.

Do you have any idea to do this? I want to make this good. I have solution, just use foreach loop, but I want to make this as good optimize as I can.

Sorry for my english.

ArrayList list = new ArrayList();
//Insert to list few objects
ArrayList specificList = get few objects from list using filter. For example Object.Name
Was it helpful?

Solution

Use Traditional loops for .Net 1.1

You said but I want to make this as good optimize as I can.

Loops are best optimizer when iterating over a collection as compared to LINQ.

Based on your example you can do this.

ArrayList list = new ArrayList();
//Insert to list few objects

ArrayList specificList = new ArrayList(); 

for (int i = 0; i < list.Count ; i++)
{
    if (((MyObject)list[i]).Name.Contains("ogrod87"))
        specificList.Add(list[i]);
}

OTHER TIPS

I think nothing is better than a loop for filtering an array in .Net 1.1.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top