gpt4 book ai didi

c# - 将 Linq 转换为列表出现 AnonymousType 错误

转载 作者:太空宇宙 更新时间:2023-11-03 11:04:17 26 4
gpt4 key购买 nike

我在 S/O 上看到过类似的错误,但修复对我来说并不直接。

Cannot implicitly convert type 'System.Collections.Generic.List<AnonymousType#1>' to 'System.Collections.Generic.List<DTD.ManagedMPS.Core.EtchVectorShapes>'

我需要做什么才能将此 linq 查询作为我的特定列表传递出去?

public List<EtchVectorShapes> GetEtchVectors(List<ViolationType> list, List<ExcelViolations> excelViolations)
{
var etchVector = new List<EtchVectorShapes>();

etchVector = (from vio in list
where excelViolations.Any(excelVio => vio.VioID.Formatted.Equals(excelVio.VioID.ToString()))
&& excelViolations.Any(excelVio => vio.RuleType.Formatted.Equals(excelVio.RuleType))
&& excelViolations.Any(excelVio => vio.VioType.Formatted.Equals(excelVio.VioType))
&& excelViolations.Any(excelVio => vio.EtchVects.Any(x => x.XCoordinate.Equals(excelVio.XCoordinate)))
&& excelViolations.Any(excelVio => vio.EtchVects.Any(y => y.YCoordinate.Equals(excelVio.YCoordinate)))

select new
{
EtchVectors = vio.EtchVects // firstOrDefault.Formatted
}).ToList();


return etchVector;
}

最佳答案

您需要将选择更改为选择新的 EtchVectorShapes{EtchVectors = vio.EtchVects}

您也不需要将 etchVector 变量初始化为新列表。

关于c# - 将 Linq 转换为列表出现 AnonymousType 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16492480/

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