IList克隆 [英] IList clone

查看:82
本文介绍了IList克隆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将IList 数据克隆到另一个Ilist (浅副本).
这是我的代码:

How can I clone an IList data to another Ilist (Shallow copy).
Here is my code:

IList lstOldList = null;
IList lstNewList;
Datagrid myDatagrid = some value;
lstOldList = myDatagrid.SelectedItems;


lstNewList = shallow copy of lstOldList ;
知道如何执行此操作吗?


lstNewList = shallow copy of lstOldList ;
Any idea how to do this?

推荐答案

System.Linq 导入到您的类文件中.

并尝试以下操作:

Import System.Linq into your class file.

And try the below:

lstNewList = lstOldList.ToList();



仅当您的项目中引用了LINQ时,以上代码才有效.

否则,您需要遍历 lstOldList 中的每个项目并将其添加到 lstNewList 中.



The above code will work only if you have LINQ referred in your project.

Else, you need to loop through each item in the lstOldList and add it into the lstNewList.


这篇关于IList克隆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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