'Searching a custom object
As a follow-up to my previous question, and continuing with the sample code in the answer there, how can I e.g. find out if a ParameterSet exists in my ParameterSetCollection with a Y parameter of "foobar"? I can write code to iterate over the ParameterSet, but it seems there should be a better way.
Solution 1:[1]
Dim parameterSets As New ParameterSetCollection
'...
If parameterSetCollection.Any(Function(ps) ps.Y = "foobar") Then
'At least one item in the collection has a Y value of "foobar".
End If
Any is a LINQ method and LINQ excels at compressing loops. That code is functionally equivalent to this:
Dim parameterSets As New ParameterSetCollection
'...
Dim match = False
For Each ps In parameterSetCollection
If ps.Y = "foobar" Then
match = True
Exit For
End If
Next
If match Then
'At least one item in the collection has a Y value of "foobar".
End If
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | user18387401 |
