C# 接口的Linq列表,接口的成员有一个字符串数组,我想要一个Linq语句来聚合对象数组中的所有字符串
我在C#中有一个接口数组,在接口中有一个成员,一个字符串列表,我试图将属性为字符串数组的接口成员数组中的所有字符串添加到一起C# 接口的Linq列表,接口的成员有一个字符串数组,我想要一个Linq语句来聚合对象数组中的所有字符串,c#,arrays,linq,object,C#,Arrays,Linq,Object,我在C#中有一个接口数组,在接口中有一个成员,一个字符串列表,我试图将属性为字符串数组的接口成员数组中的所有字符串添加到一起 IPackingFlowEvaluation[] public interface IPackingFlowEvaluation { IPackingFlow PackingFlow { get; } int Priority { get; } bool CanUse { get; } string[] Reasons { get
IPackingFlowEvaluation[]
public interface IPackingFlowEvaluation
{
IPackingFlow PackingFlow { get; }
int Priority { get; }
bool CanUse { get; }
string[] Reasons { get; }
}
我想要一个linq语句,它将接口成员数组的所有字符串添加到一个大的字符串列表中。一个巨大的原因列表,包含接口数组中的所有原因,接口数组中的成员本身具有字符串数组 听起来你在追求
SelectMany
var reasons = source.SelectMany(e => e.Reasons).ToList();
其中
source
指的是iPackflowEvaluation[]
您需要使用SelectMany()
才能达到此效果
var allReasons = array.SelectMany(i => i.Reasons.ToList()).ToList();
SelectMany
中的ToList()
是多余的。没有它你会过得更好。