如何有效地从两个字符串数组中删除重复项?我想从string[] a
单独的 a 中删除所有重复项string[] b
例如
a = { "1", "2", "3", "4"};
b = { "3", "4", "5", "6"};
我正在寻找的结果就是
c = { "5", "6"};
var final = b.Except(a).ToList();
Enumerable.Except produces set difference of two sequences
var c = b.Except(a).ToArray(); // gives you { "5", "6" }
YOu can try using this:-
List<string[]> moves = new List<string[]>();
string[] newmove = { piece, axis.ToString(), direction.ToString() };
moves.Add(newmove);
moves.Add(newmove);
moves = moves.Distinct().ToList();
or try this:-
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());
}
}
}
}