Question LINQ on array of objects

bufer24

Active member
Joined
Mar 27, 2008
Messages
35
Programming Experience
3-5
Let´s say I have an array (I named it "Points") of objects. Each object has a custom property called for example "Selected". The property type is Boolean.
Can I use LINQ to determine the INDEX of the element in the "Points" array where "Selected=True"? (I´ve ensured that only one element can have the property set to True).

I know how to do it the "old way" (using a loop), but it would be better getting rid of any loops.
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,589
Location
Norway
Programming Experience
10+
VB.NET:
Dim indexes = From x In points Where x.Selected Select Array.IndexOf(points, x)
 
Top Bottom