问一个List<>的基础问题
private void Process(List<string> list1,out List<string> list1_out)
{
list1_out = list1;
for (int i = 0; i + 1 < list1.Count; i++)
{
if (某个条件)
{
list1_out.RemoveAt(i);
}
}
}
原本以为是仅去除list1_out内的值,谁知list1内的也一样被remove了
请问该怎么写才能保证list1内的东西没被remove,仅remove "list1_out"内的,谢谢
------解决方案--------------------
C# code
private void Process<T>(List <T> list1,out List <T> list1_out)
{
list1_out = new List<T>(list1);
for (int i = 0; i + 1 < list1.Count; i++)
{
if (true/*某个条件*/)
{
list1_out.RemoveAt(i);
}
}
}