In SQL, you can use the following syntax:
SELECT *
FROM MY_TABLE
WHERE VALUE_1 IN (1, 2, 3)
Is there an equivalent in C#? The IDE seems to
List.Contains()
is I think what you're looking for. C# has in
keyword
and not an operator
which serves completely different purpose then what you're referring in SQL.
There are two ways you can use in
keyword in C#. Assume you have a string[] or List in C#.
string[] names; //assume there are some names;
//find all names that start with "a"
var results = from str in names
where str.StartsWith("a")
select str;
//iterate through all names in results and print
foreach (string name in results)
{
Console.WriteLine(name);
}
Referring your edit, I'd put your code this way to do what you need.
int myValue = 1;
List checkValues = new List { 1, 2, 3 };
if (checkValues.Contains(myValue))
// Do something