在 C# 中使用 For Each 组合两个列表

Mel*_*vin 3 c# list

我在 C# 中有两个列表对象,如下所述

List A

[0]
    Count="0",
    CountType="0",
    InvTpeCode="DLX"
[1]
    Count="0",
    CountType="0"
    InvTpeCode="STD"

List B

[0]
    Count="2",
    CountType="17"
[1]
    Count="12",
    CountType="14"
Run Code Online (Sandbox Code Playgroud)

我尝试使用 foreach 用列表 b 值更新列出 a 值,但不幸的是我无法带来所需的输出。

注意:两个列表的大小相同

fub*_*ubo 5

除了for-loop 之外,你还可以使用Zip

var result = A.Zip(B, (a, b) => new Item {
                             InvTpeCode = a.InvTpeCode,
                             CountType = b.CountType, 
                             Count = b.Count });
Run Code Online (Sandbox Code Playgroud)