繁体   English   中英

从两个字符串数组中删除重复项c#

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM