A solenoid is a long straight insulated wire, such as a copper coil, often wrapped around a cylinder-shaped body. The diameter of the solenoid is lesser than its length. It produces a magnetic field when electric current is passed through it.
Magnetic field produced by a solenoid and by bar is shown below:
On comparing field lines produced by a solenoid with that produced by a bar magnet, we observe that they are very much identical. Thus, a solenoid acts as a bar magnet when current is passed through it.