Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VB.NET/C# Comparison Operator for to test for set membership - like the IN Operator for SQL

Tags:

.net

vb.net

so in SQL you can do something like:

 WHERE title IN('title1','title2','title3')

to test for set membership (assuming i'm using the right phrase here). how can I do this in VB.NET/C#.NET?

Example:

 IF textMyTitle.text IN ("title1","title2","title 3") THEN
 'Take Action
 End If

Obviously the IN part of that statement doesn't work...whats the logical equivalent in .NET?

like image 675
Albert Avatar asked Dec 18 '22 01:12

Albert


1 Answers

Try this:

Dim titles As New List(Of String)()
titles.Add("title1")
titles.Add("title2")
titles.Add("title3")

If titles.Contains(textMyTitle.text) Then
    // Do something here
End If
like image 81
Andrew Hare Avatar answered Jun 03 '23 12:06

Andrew Hare