Find item in array of objects VB.NET
I'm making a function that searchs an array of Customers and returns a Customer object by a given ID. I'm trying to do so with Lambda Expressions,and this is what I have so far:
Public Shared Function FindCustomer(ByVal ID As Integer) As cCustomer
Dim customer as New cCustomer = _ _
Array.Find(arrCustomers, Function(c as cCustomer) c.ID = ID)
Return customer
End Function
However,this throws a Null Reference exception at 'c',and I have no idea how to solve this,any help is welcome :).
EDIT: I get the error when I call the function like:
dim cust as New cCustomer
cust = FindCustomer(5)
MsgBox(cu开发者_Go百科st.Name)
'BANG
Thx.
One of the customers in your array is null.
精彩评论