问题
I have a question. Imagine that in vb.net, fill a array of structure with a lot of items. For example, here I declare the structure called Persons:
Public structure Persons
Dim name as string
Dim age as integer
End structure
Then, I declare a variable that is a array of persons, for make a list of friends, like this:
Dim friends() as Persons
friends(0).name = "Sebastian"
friends(0).age = 19
friends(1).name = "Michael"
friends(1).age = 34
...
So, there are any form to locate where is the position of "Sebastian"?? In other words. If I would know if "Sebastian" exist in any friends(i).name, and, if exist, returns me the position (i), how I can do this??
Thanks
回答1:
Try this:
Dim i As Integer = Array.FindIndex(friends, Function(f) f.name = "Michael")
The variable i should have the position of the person named "Michael".
来源:https://stackoverflow.com/questions/28998204/find-item-in-array-of-structure