0
List<String> s1;
List<String> s2;
我要到n项从S1移动到s2的从一个列表移动元素到其他列表
say s1={"a","b","c"}
s2={"d","e","f"}
移动2个元素从S1到S2将使
s1={"c"}
s2={"d","e","f","a","b"}
是什么实现这一目标的好方法?
List<String> s1;
List<String> s2;
我要到n项从S1移动到s2的从一个列表移动元素到其他列表
say s1={"a","b","c"}
s2={"d","e","f"}
移动2个元素从S1到S2将使
s1={"c"}
s2={"d","e","f","a","b"}
是什么实现这一目标的好方法?
var s1 = new List<string>() { "a", "b", "c" };
var s2 = new List<string>() { "d", "e", "f" };
s2.AddRange(s1.Take(2));
s1.RemoveRange(0, 2);
使用项目的索引移动(在这种情况下,0):
string item = s1[0];
s1.Remove(item);
s2.Add(item);
注意的是,如果一个列表包含重复的值,这将无法正常工作。 – Servy