如何從兩個字符串數組中有效地刪除重複項?我想刪除所有從string[] a
是在一個單獨的string[] b
從兩個字符串數組中刪除重複項#
例如
a = { "1", "2", "3", "4"};
b = { "3", "4", "5", "6"};
重複的我期待的結果也只是
c = { "5", "6"};
如何從兩個字符串數組中有效地刪除重複項?我想刪除所有從string[] a
是在一個單獨的string[] b
從兩個字符串數組中刪除重複項#
例如
a = { "1", "2", "3", "4"};
b = { "3", "4", "5", "6"};
重複的我期待的結果也只是
c = { "5", "6"};
Enumerable.Except產生設置兩個序列
var c = b.Except(a).ToArray(); // gives you { "5", "6" }
您可以嘗試使用此: -
List<string[]> moves = new List<string[]>();
string[] newmove = { piece, axis.ToString(), direction.ToString() };
moves.Add(newmove);
moves.Add(newmove);
moves = moves.Distinct().ToList();
或試試這個: -
var c = b.Except(a).ToArray();
static void Main(string[] args)
{
Foo(m.Length-1);
}
static string m = "1234";
static string c = "3456";
static int ctr = 0;
static void Foo(int arg)
{
if (arg >= 0)
{
Foo(arg - 1);
Console.Write(m[arg].ToString());
for (int i = ctr; i < m.Length; i++)
{
if (c[i].ToString() == m[arg].ToString())
{
ctr++;
break;
}
}
if(arg==m.Length-1)
{
for (int i = ctr; i <m.Length; i++)
{
Console.Write(c[i].ToString());
}
}
}
}
什麼與 「2」 和 「1」 發生的差異?有一次出現...他們是否應該在結果中? – nemesv
@poplitea重複的問題是不同的,它只給出1個數組中的重複不是兩個不同的數組 – pyCthon
@nemesv沒有數組b會是 – pyCthon