[英]remove duplicates from two string arrays c#
如何有效地從兩個字符串數組中刪除重復項? 我想從刪除所有重復string[] a
是在一個單獨的string[] b
例如
a = { "1", "2", "3", "4"};
b = { "3", "4", "5", "6"};
我正在尋找的結果只是
c = { "5", "6"};
var final = b.Except(a).ToList();
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());
}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.