Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 比较两个集合或列表的最快算法_C#_Performance_Linq - Fatal编程技术网

C# 比较两个集合或列表的最快算法

C# 比较两个集合或列表的最快算法,c#,performance,linq,C#,Performance,Linq,我需要.NET C#中最快的算法来比较两个大型集合(每个集合中有200000条记录)。我需要用集合2的每一行验证集合1的每一行,并返回集合1中在集合2中具有重复记录的行 请推荐一个更快的linq查询或查找表。记录如A2368FG、AD5686、B678SD、C68AGFD private bool CheckValidCode(string stdCode, List<COde> CodeMap, out int count) { bo

我需要.NET C#中最快的算法来比较两个大型集合(每个集合中有200000条记录)。我需要用集合2的每一行验证集合1的每一行,并返回集合1中在集合2中具有重复记录的行

请推荐一个更快的linq查询或查找表。记录如A2368FG、AD5686、B678SD、C68AGFD

    private bool CheckValidCode(string stdCode, List<COde> CodeMap, out int count)
        {
            bool bRetVal = true;
            count = 1;
                try
                {

              List<COde> tempCodeMap = new List<COde>();

              for (int i = 0; i < CodeMap.Count; i++)
              {
                  if (CodeMap[i].StandardCode == (stdCode))
                  {
                      tempCodeMap .Add(customerCodeMappings[i]);
                      if (CodeMap[i + 1].StandardCode == (stdCode))
                      {
                          tempCodeMap .Add(CodeMap[i + 1]);
                      }
                      break;
                  }
              }
    return tempCodeMap ;
    }
}
private bool CheckValidCode(字符串stdCode,列表
CodeMap,out int count)
{
bool-bRetVal=true;
计数=1;
尝试
{
ListtempCodeMap=新列表();
for(int i=0;i
它们各自是简单的字符串对象吗?如果是这样,您可以使用

Collection1.Intersect(collection2)
这将返回两个集合中存在的所有记录


这就是你想要的吗?您的问题不清楚您是否希望查找collection1中存在的记录以及collection2中多次存在的记录。如果这就是你想要的,你需要深入挖掘。

Intersect()
等方法应该会有所帮助

不要使用集合,请使用
Set
类(或将集合转换为集合)。
然后你可以调用像
Intersect()
这样的方法,它只是更快(但你用内存换取速度)

是的..你的第二个语句就是我想要的..Intersect将返回我的公共记录。我想查找collection1中存在的记录以及Collection2中多次存在的记录。您可以按集合进行分组,该集合是一个组中有多个记录的筛选器(因此满足“多次”条件),然后根据需要使用Intersect或Except。