I am new to VB.NET and I keep telling myself there must be a better way to do what I need to do several times a day which is look into a list
and see if that one field is set to true
anywhere in that list.
So far, I've been using the For Each
statement:
For Each player In ListOfPlayers
If player.isActive Then
... do something ...
End If
Next
But I know some of the other languages can do something like:
if ListOfPlayers(*).isActive == true
开发者_如何学Gowhich just seems more concise and to the point. Any suggestion?
As proposed by Bobby in the comments, use LINQ:
If ListOfPlayers.Any(Function (p) p.IsActive) Then …
This asks whether there’s any player (Any
) for which IsActive
is True
.
精彩评论