cloudflight
2023-12-02 1a5ef6b2bf25de50b685b44299d9a049a2feac80
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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++;
                }
            }
        }
    }
}