Why `null >= 0 && null

Your real question seem to be: Why: null >= 0; // true But: null == 0; // false What really happens is that the Greater-than-or-equal Operator (>=), performs type coercion (ToPrimitive), with a hint type of Number, actually all the relational operators have this behavior. null is treated in a special way by the Equals … Read more

Comparing two collections for equality irrespective of the order of items in them

It turns out Microsoft already has this covered in its testing framework: CollectionAssert.AreEquivalent Remarks Two collections are equivalent if they have the same elements in the same quantity, but in any order. Elements are equal if their values are equal, not if they refer to the same object. Using reflector, I modified the code behind … Read more

Determine if 2 lists have the same elements, regardless of order? [duplicate]

You can simply check whether the multisets with the elements of x and y are equal: import collections collections.Counter(x) == collections.Counter(y) This requires the elements to be hashable; runtime will be in O(n), where n is the size of the lists. If the elements are also unique, you can also convert to sets (same asymptotic … Read more

In Objective-C, what is the equivalent of Java’s “instanceof” keyword?

Try [myObject class] for returning the class of an object. You can make exact comparisons with: if ([myObject class] == [MyClass class]) but not by using directly MyClass identifier. Similarily, you can find if the object is of a subclass of your class with: if ([myObject isKindOfClass:[AnObject class]]) as suggested by Jon Skeet and zoul.

Python if not == vs if !=

Using dis to look at the bytecode generated for the two versions: not == 4 0 LOAD_FAST 0 (foo) 3 LOAD_FAST 1 (bar) 6 COMPARE_OP 2 (==) 9 UNARY_NOT 10 RETURN_VALUE != 4 0 LOAD_FAST 0 (foo) 3 LOAD_FAST 1 (bar) 6 COMPARE_OP 3 (!=) 9 RETURN_VALUE The latter has fewer operations, and is therefore … Read more

What’s the difference between IEquatable and just overriding Object.Equals()?

The main reason is performance. When generics were introduced in .NET 2.0 they were able to add a bunch of neat classes such as List<T>, Dictionary<K,V>, HashSet<T>, etc. These structures make heavy use of GetHashCode and Equals. But for value types this required boxing. IEquatable<T> lets a structure implement a strongly typed Equals method so … Read more

equals vs Arrays.equals in Java

array1.equals(array2) is the same as array1 == array2, i.e. is it the same array. As @alf points out it’s not what most people expect. Arrays.equals(array1, array2) compares the contents of the arrays. Similarly array.toString() may not be very useful and you need to use Arrays.toString(array).

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)