更新时间:2023-11-18 20:16:10
尝试一下:
Dim i As Integer = Array.FindIndex(friends,Function(f)f.name ="Michael")
变量i应该具有名为"Michael"的人的位置.
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
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".