I created this in Adobe Illustrator 2022 version 26.4.1. There’s also a short video for this tutorial.
Select the Line Segment Tool from the toolbar. It’ll be the first one in the dropdown list – above the Arc, Spiral, Rectangular Grid and the Polar Grid Tool.
I’ve selected no fill, black for stroke and 1pt for stroke weight.
Then I opened the Stroke panel by clicking on Stroke and there, I checked the box next to Dashed Line and entered 2pt in the first dash field. You can enter other values and also enter a gap value to get different results.
I then dragged out a line on the art board while holding down shift to draw the dashed line.