How to wire the 3-contact limit switch for endstop

These switches are almost always labeled:

There will be a C or Com for the common terminal. NC is the normally closed pin, and the NO is the normally open pin. For this pictured switch, the outside two terminals are used (as indicated by Drefus). Polarity does not matter. You can connect these two pins to the S and GND pins of your control board in either order.

You can also test it with an ohmmeter. The two terminals that are connected when the switch is not pressed will be Com and NC.