开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜