Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从列表对象到具有列表属性的一个对象的Linq_C#_String_Linq_List - Fatal编程技术网

C# 从列表对象到具有列表属性的一个对象的Linq

C# 从列表对象到具有列表属性的一个对象的Linq,c#,string,linq,list,C#,String,Linq,List,我正在尝试使用Linq从MyObject的列表中选择属性ProductColor到属性AllProductColor 我希望它是这样的 destinationObject有一个元素列表,其中一种颜色等于一个元素。您只需将尝试的第一个查询放入第二个查询,如下所示: destinationObject = MyObjectList.Select(x => new ObjectToSelectInto() { AllProductColor

我正在尝试使用Linq从MyObject的列表中选择属性ProductColor到属性AllProductColor

我希望它是这样的


destinationObject有一个元素列表,其中一种颜色等于一个元素。

您只需将尝试的第一个查询放入第二个查询,如下所示:

 destinationObject = MyObjectList.Select(x =>
        new ObjectToSelectInto()
        {
           AllProductColors = MyObjectList.Select(y => y.ProductName).ToList(),
           ImgUrl = x.ImgUrl,
           ProductName = x.ProductName
       }).First();

我不太明白你在尝试什么,但听起来SelectMany可能是正确的调用?这有什么意义?x、 MaterialColor.ToCharray0,x.MaterialColor.Length您的字符串已经是一个字符数组了?@Selman22一点都没有?只是试验,试图掌握产生的结果。真的那么不清楚吗?是的,请更清楚地解释你的问题。并告诉我们预期的结果。我试图理解你,但我仍然不明白你到底想要什么。费克,为什么我没有想到这一点!!好的!!
 destinationObject = MyObjectList.Select(x =>
        new ObjectToSelectInto()
        {
           AllProductColors = MyObjectList.Select(y => y.ProductName).ToList(),
           ImgUrl = x.ImgUrl,
           ProductName = x.ProductName
       }).First();