int max = ~0;
What does it mean?
As others have stated, ~ is the bitwise negation operator. It will take all bits of the integer value and toggles 0 and 1 (0 -> 1 and 1 -> 0).
~0 equals to -1 for a signed integer or Int32.
Usually either ~0 or -1 is used as the "ALL inclusive" mask (asterisk) when you are implementing a layer-based filtering system of some kind where you use a "layerMask" argument which by default equals to -1 meaning that it will return anything (does not filter). The filter is indeed using a AND operation (valueToFilter & layerMask).
valueToFilter & -1 will always be non-zero if valueToFilter is also non-zero. Zero otherwise.