When a current passes through it, it creates a nearly uniform magnetic field inside. Solenoids can convert electric current to mechanical action, and so are very commonly used as switches. The magnetic field within a solenoid depends upon the current and density of turns.