简体   繁体   中英

Copy from one arrayList to another

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

我认为没有什么比.Net 1.1中过滤数组的循环更好的了。

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]);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM