gpt4 book ai didi

C# 从匿名类型中选择字符串列表

转载 作者:太空宇宙 更新时间:2023-11-03 19:39:41 25 4
gpt4 key购买 nike

我有以下 LINQ,我需要将结果作为列表返回,但我收到错误:

Cannot implicitly convert type System.Collections.Generic.IEnumerable<<anonymous type: string emis>> to System.Collections.Generic.List<string>. An explicit conversion exists (are you missing a cast?)

如何返回字符串列表?

List<string> emisList = (
from p in subproductTypeyProduct
join q in dbEntitiesParams.PARAM_Rule
on new { p.ProductType, p.SubProductTypeCode }
equals new { ProductType = q.ProductTypeCode, SubProductTypeCode = q.SubProductCode }
select new { q.emis });

最佳答案

无需投影匿名类型。只是简单的字符串。将 select new { q.emis } 替换为 select q.emis

关于C# 从匿名类型中选择字符串列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55434258/

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