我想比较一个枚举数组与单个枚举实例。将枚举数组或列表传递给函数
介绍
我有一个枚举类型数组\目录
Public Enum InvalidEmailType
Multiple_Updates
Period_Before_At_Sign
Missing_Dot_Com
End Enum
Public Class CustomerClass
Public CustomerName As String
Public ErrorTypeList = [Enum].GetValues(GetType(InvalidEmailType))
Public ErrorDescription As String
End Class
根据被添加到列表中什么样的价值观一类,我想运行特定的代码。
为了做到这一点,我的整个列表比较单一实例:
If UpdateCustomer.MatchErrorType(customer.ErrorTypeList, InvalidEmailType.Trailing_Period) = True Then
'Run Code
End If
功能里面我比较反对单一实例的整个列表。
换句话说,我通过类里面的整个列表循环,并检查值有:
Public Shared Function MatchErrorType(CustomerErrortypeList As List(Of InvalidEmailType), EmailError As InvalidEmailType) As Boolean
MatchErrorType = False
Dim Found As InvalidEmailType = CustomerErrortypeList.Where(Function(match) match.ToString = EmailError.ToString).OrderByDescending(Function(match) match.ToString).FirstOrDefault()
If Found > 0 Then
MatchErrorType = True
End If
End Function
这里的问题是: 如何声明数组\列表中函数参数?
名单(共InvalidEmailType)不工作,因为我得到一个错误投
无法投类型的对象EmailValidationReport.InvalidEmailType []'键入“System.Collections.Generic.List`1 [ EmailValidationReport.InvalidEmailType]'
该列表包含在客户类 –
@InternetEngineer好的,你可以在你调用该函数之前做到这一点,查看更新的答案。 – Magnus
演员表不起作用: 找不到类型为'InvalidEmailType()'的公共成员'Cast' –