在结构数组中查找项目 [英] Find item in array of structure
问题描述
我有一个问题.想象一下,在vb.net中,用很多项目填充结构数组.例如,在这里我声明一个名为Persons的结构:
公共结构人员昏暗的名字作为字符串暗淡年龄为整数末端结构
然后,我声明一个变量,该变量是一个由人组成的数组,用于列出一个朋友列表,如下所示:
将Persons()昏暗化为人物friends(0).name =塞巴斯蒂安"朋友(0).age = 19friends(1).name =迈克尔"朋友(1).age = 34...
因此,可以使用任何形式来定位塞巴斯蒂安"的位置??换句话说.如果我想知道"Sebastian"是否存在于任何friends(i).name中,并且如果存在的话,将位置(i)返回给我,我该怎么做?
谢谢
尝试一下:
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".
这篇关于在结构数组中查找项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!