@Webster's answer is a good one. A pattern brush is probably the easiest solution.
Just to offer an alternative method.One could use a gradient applied to a stroke. This offers a little more adjustment options than a pattern brush, but it does take more effort to set up.
First create a gradient of alternating colors and hard edges. To do this, you set a color stop, then change it's position. Ultimately having 2 color stops of alternating colors in the same position on the gradient.
Notice that when the positions are adjust to be the same there's a hard edge. This particular gradient changes color every 10%, but if you want more frequent changes you can adjust for every 5% or whatever works for you. Changing the percentage after the fact is a tad cumbersome, but not difficult (actually easier to start from scratch than try and adjust what's there).
Once you have the gradient set up, just apply it to the stroke. You can then set the angle for the gradient to whatever you want. And increasing/decreasing the stroke weight will change the thickness of the dashes. The biggest benefit here it the ability to alter the gradient angle and thus the angle of your dashes. Pattern brushes don't really do that (not to mention the corners of pattern brushes).
Again, not as easy as a pattern brush, but sometimes more useful.
(To get a dash in the lower left AND upper right corners your gradient needs to start and stop with the same color. My gradient doesn't so it leaves the white in the lower left corner.)