in-operator

Java in operator

守給你的承諾、 提交于 2019-11-27 12:46:24
问题 For the one millionth time, I would have liked to use an IN operator in Java, similar to the IN operator in SQL. It could just be implemented as compiler syntactic sugar. So this if (value in (a, b, c)) { } else if (value in (d, e)) { } ...would really be awesome. In fact, the above is the same as the rather verbose (and not adapted for primitives) construct here: if (Arrays.asList(a, b, c).contains(value)) { } else if (Arrays.asList(d, e).contains(value)) { } Or like this for int , long and

Is there a C# IN operator?

自作多情 提交于 2019-11-27 00:49:31
问题 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 recognise "in" as a keyword, but I don't seem to be able to find any information on it. So, is it possible to do something like the following: int myValue = 1; if (myValue in (1, 2, 3)) // Do something Instead of int myValue = 1; if (myValue == 1 || myValue == 2 || myValue == 3) // Do something 回答1: If you wanted to write .In then you could create an

Override Python's 'in' operator?

匆匆过客 提交于 2019-11-26 14:20:59
If I am creating my own class in Python, what function should I define so as to allow the use of the 'in' operator, e.g. class MyClass(object): ... m = MyClass() if 54 in m: ... Ignacio Vazquez-Abrams MyClass.__contains__(self, item) pthulin A more complete answer is: class MyClass(object): def __init__(self): self.numbers = [1,2,3,4,54] def __contains__(self, key): return key in self.numbers Here you would get True when asking if 54 was in m: >>> m = MyClass() >>> 54 in m True See documentation on overloading __contains__ . You might also want to take a look at an infix operator override

How to use php array with sql IN operator?

这一生的挚爱 提交于 2019-11-26 09:41:10
问题 I have and array with two values and I want to use it with sql IN operator in select query. Here is the structure of my table id comp_id 1 2 2 3 3 1 I have an array $arr which have two values Array ( [0] => 1 [1] => 2 ) I want to fetch the record of comp_id 1 and comp_id 2. So I wrote the following query. SELECT * from table Where comp_id IN ($arr) But it does not return the results. 回答1: As you have plain integers can just do... $sql = "SELECT * FROM table WHERE comp_id IN (".implode(',',

Why does javascript's “in” operator return true when testing if 0 exists in an array that doesn't contain 0?

Deadly 提交于 2019-11-26 03:58:00
问题 Why does the \"in\" operator in Javascript return true when testing if \"0\" exists in array, even when the array doesn\'t appear to contain \"0\"? For example, this returns true, and makes sense: var x = [1,2]; 1 in x; // true This returns false, and makes sense: var x = [1,2]; 3 in x; // false However this returns true, and I don\'t understand why: var x = [1,2]; 0 in x; 回答1: It refers to the index or key, not the value. 0 and 1 are the valid indices for that array. There are also valid

Override Python's 'in' operator?

空扰寡人 提交于 2019-11-26 03:51:38
问题 If I am creating my own class in Python, what function should I define so as to allow the use of the \'in\' operator, e.g. class MyClass(object): ... m = MyClass() if 54 in m: ... 回答1: MyClass.__contains__(self, item) 回答2: A more complete answer is: class MyClass(object): def __init__(self): self.numbers = [1,2,3,4,54] def __contains__(self, key): return key in self.numbers Here you would get True when asking if 54 was in m: >>> m = MyClass() >>> 54 in m True See documentation on overloading