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