asp.net-.除了抛出异常,还有哪些处理方式?

2026-03-30 11:371阅读0评论SEO问题
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计486个文字,预计阅读时间需要2分钟。

asp.net-.除了抛出异常,还有哪些处理方式?

我有一段伪代码如下:plaintextPublic 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 unavailableM As List(Of Manufacturer)简化改写如下:plaintext公共函数获取可用制造商() 返回 Manufacturer 列表 '首先获取所有活跃订单并提取制造商 Dim sos As OrderForm 列表=获取按状态查询表单(库存状态.建设中) Dim 不可用制造商 As Manufacturer 列表

我有以下代码:

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,7,10} Result: {1,2,3,4,6,8,9}

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

asp.net-.除了抛出异常,还有哪些处理方式?

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()

本文共计486个文字,预计阅读时间需要2分钟。

asp.net-.除了抛出异常,还有哪些处理方式?

我有一段伪代码如下:plaintextPublic 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 unavailableM As List(Of Manufacturer)简化改写如下:plaintext公共函数获取可用制造商() 返回 Manufacturer 列表 '首先获取所有活跃订单并提取制造商 Dim sos As OrderForm 列表=获取按状态查询表单(库存状态.建设中) Dim 不可用制造商 As Manufacturer 列表

我有以下代码:

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,7,10} Result: {1,2,3,4,6,8,9}

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

asp.net-.除了抛出异常,还有哪些处理方式?

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()