将集合项目复制到.NET中的另一个集合 [英] Copy collection items to another collection in .NET

查看:55
本文介绍了将集合项目复制到.NET中的另一个集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在.NET(VB)中,我如何才能将一个集合中的所有项目取走,然后将它们添加到第二个集合中(而又不丢失第二个集合中先前存在的项目)?我正在寻找比这更有效率的东西:

In .NET (VB), how can I take all of the items in one collection, and add them to a second collection (without losing pre-existing items in the second collection)? I'm looking for something a little more efficient than this:

For Each item As Host In hostCollection1
    hostCollection2.Add(item)
Next

我的集合是通用集合,继承自基类-Collection(Of)

My collections are generic collections, inherited from the base class -- Collection(Of )

推荐答案

您可以使用AddRange: hostCollection2.AddRange(hostCollection1).

You can use AddRange: hostCollection2.AddRange(hostCollection1).

这篇关于将集合项目复制到.NET中的另一个集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆