Array.FindIndex 异常

时间:2021-02-24 21:23:29

标签: arrays vb.net exception

我使用如下的 lambda 表达式调用 Array.FindIndex 以在我的“源”数组中查找索引...其中值与我的 LSource 对象中的“LName”属性匹配)

'代码在此处输入一个 NEW LSource to Add OR 以增加现有 LSource 的计数:

Dim Indx as integer = Array.FindIndex(Source, Function(x As LSource) x.LName.ToLower = curSource)
    If indx = -1 then
If Source Is Nothing Then ReDim Preserve Source(0) Else ReDim Preserve Source(UBound(Source) + 1)
    Dim myNewLSource AS New LSource
     myNewLSource.LName = "John"
     myNewLSource.Whatever = "Whatever"
     myNewLSource.Count = 0
    Source(UBound(Source)) =  myNewLSource
    Else
    Source(indx).Count +=1
    End if

我收到错误对象引用未设置为对象(x 什么都没有)。尝试在 lamda 中实例化它,但它说不允许。

谢谢

0 个答案:

没有答案