1

I have a string value in which I need to do a compare on in an IF statement. However, I need to check the compare in a List object that contains a type string, how do I go about this in one line if possible (or using LINQ)?

For example I was going down the lines off

If "example" = m_listObject.ForEach(Function(x) x.stringValue)) Then
...

Of course this won't work but I hope you know what I mean,

Yes, I could do it in a for each or a for but I want to use LINQ if possible.

Thanks

3 Answers 3

3

You can use Any():

If m_listObject.Any(Function(f) f.stringValue = "example") Then
    'some more code
End If
Sign up to request clarification or add additional context in comments.

Comments

2

Use Any:-

If(m_listObject.Any(Function(x) x.stringValue = "example")) Then

Comments

0

You can use Find :

If m_listObject.Find(Function(x) x.stringValue.equals("example", StringComaprison.InvariantCultureIgnoreCase)).count > 0 Then
    ...
End If

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.