废话不多说,看代码:
方法一:
list
list
方法二:
it is a one liner using linq.
list
list
// this will copy all the items from list 1 to list 2
list1.foreach(i => list2.add(i));
方法三:
using system;
using system.linq;
using system.collections.generic;
using system.diagnostics;
namespace delegates
{
class x
{
public int id { get; set; }
public string name { get; set; }
}
class y
{
public int id { get; set; }
public string name { get; set; }
}
class program
{
static void main(string[] args)
{
list
for (int i = 0; i x.add(new x { id = i, name = string.format("x_{0}", i.tostring()) });
// copy x to y
list
debug.assert(x.count == y.count);
}
}
}
更多 C# List 复制克隆副本相关文章请关注PHP中文网!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号