using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace CommonBase
|
{
|
public class QuickListTreat
|
{
|
public static void MatchAndTreat(List<dynamic> listA_source, List<dynamic> listB_source, Action<dynamic, dynamic> treat)
|
{
|
// 对 List A 和 List B 按 Key 进行排序
|
var listA = listA_source.OrderBy(a => a.Key).ToList();
|
var listB = listB_source.OrderBy(b => b.Key).ToList();
|
int indexA = 0;
|
int indexB = 0;
|
|
while (indexA < listA.Count && indexB < listB.Count)
|
{
|
if (listA[indexA].Key == listB[indexB].Key)
|
{
|
treat(listA[indexA], listB[indexB]);
|
indexA++;
|
indexB++;
|
}
|
else if (listA[indexA].Key < listB[indexB].Key)
|
{
|
indexA++;
|
}
|
else
|
{
|
indexB++;
|
}
|
}
|
}
|
}
|
}
|