gpt4 book ai didi

c# - 生成由 3 个不同的 "sub-arrays"组成的项目数组

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:34:19 24 4
gpt4 key购买 nike

我有一个类:

class All{
A a;
B b;
C c;
}

现在我得到 3 个数组:

A[] as;
B[] bs;
C[] cs;

每一个都可以为空(length=0)或null。
我需要创建一个包含至少一个元素的数组的 Alls 对象列表(我不需要空对象)。

For example:
A[] as={a1, a2};
B[] bs{};
C[] cs{c1, c2};
=> Result: All[] = {
All{a: a1, b:null, c:null},
All{a: a1, b:null, c:c1},
All{a: a1, b:null, c:c2},
All{a: a2, b:null, c:null},
All{a: a2, b:null, c:c1},
All{a: a2, b:null, c:c2}
All{a: null, b:null, c:c1},
All{a: null, b:null, c:c2}
//All{a: null, b:null, c:null} -> This is an empty object and I don't need it
};

如何生成 All[]?

最佳答案

这是您要找的吗? (虽然你可能需要润色一下)

List<A> awithnull = as.ToList();
List<B> bwithnull = bs.ToList();
List<C> cwithnull = cs.ToList();

awithnull.Add(null);
bwithnull.Add(null);
cwithnull.Add(null);

var result = from ae in awithnull
from be in bwithnull
from ce in cwithnull
where (!(ae==null && be ==null && ce == null))
select new All() {a = ae, b = be, c = ce};

关于c# - 生成由 3 个不同的 "sub-arrays"组成的项目数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5780092/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com