加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – .除了抛出异常

发布时间:2020-12-16 09:19:14 所属栏目:asp.Net 来源:网络整理
导读:我有以下代码: Public Shared Function GetAvailableManufacturers() As List(Of Manufacturer) 'first get all the live orders and extract their mfrs' Dim sos As List(Of OrderForm) = GetFormsByStatus(StockStatus.Building) Dim unavailableMfrs As
我有以下代码:

Public Shared Function GetAvailableManufacturers() As List(Of Manufacturer)
    'first get all the live orders and extract their mfrs'
    Dim sos As List(Of OrderForm) = GetFormsByStatus(StockStatus.Building)
    Dim unavailableMfrs As New List(Of Manufacturer)
    For Each so As StockingOrder In sos
        unavailableMfrs.Add(so.Source)
    Next

    'then remove all mfrs with an open SO from a list of all mfrs'
    Dim allMfrs As List(Of Manufacturer) = Manufacturer.GetManufacturers
    Return allMfrs.Except(unavailableMfrs) <----- error here
End Function

解释上面做了什么:

> GetFormsByStatus()不言自明
> GetManufacturers()返回数据库中所有制造商的列表

我想获得制造商的想法是获取我的开放表格中所有制造商的清单,然后获得所有制造商的清单,并排除第一个清单中的所有制造商,如图所示(伪):

List A: {1,2,3,4,5,6,7,8,9,10}
List B: {5,10}
Result: {1,9}

我已根据this article设置了我的制造商类,以便可以进行比较,但我仍然收到此错误:

Unable to cast object of type ‘<ExceptIterator>d__92'1[csCore.Manufacturer]' to type ‘System.Collections.Generic.List'1[csCore.Manufacturer]‘.

我一开始认为,因为在测试期间GetFormsByStatus()返回0结果可能会导致问题,但如果提供的列表有0项,则Except()不起作用是没有意义的.谁能发现我做错了什么?

非常感谢!

解决方法

该函数需要List(Of Manufacturer)返回类型,而不是IEnumerable(Of Manufacturer),因此在返回值中添加.ToList()应修复它:

Return allMfrs.Except(unavailableMfrs).ToList()

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读