Skip to content

Example 1 Align by equals

Chris McGrath edited this page Dec 28, 2019 · 4 revisions

For this part we will be working with the following example

using System;

namespace AlignmentTest
{
    public enum State
    {
        Queensland = 1,
        NewSouthWales = 2,
        Victoria = 4,
        WesternAustralia = 8,
        SouthAustralia = 16,
        Tasmania = 32,
        NorthernTerritory = 64,
        AustralianCapitalTerritory = 128
    }
}

It's a common case where you have values attached to each enum.

There are some conditions you might want to ensure about this

  • You want to know that each State has a different number
  • You probably want them ordered by that number
  • In some cases they should be treated as flags so they should be powers of 2.

At a quick glance, none of this is clearly shown.

However, we can select the lines and perform align by equals (shortcut Ctrl Equals Equals)…

Before

Before

After

After

We can easily see each number is unique. The shape of our code gives us an indication that the numbers are getting bigger, and for a more through test we can quickly looking down a single column. The intent of this code is now much clearer.

We can further improve this using column marking. (Note: May not be available or may differ in your IDE, this guide works with Visual Studio & Notepad++)

Put the marker in front of the one, press Alt Shift then press the down arrow until you reach the 64, and press space. Now press Alt Shift again and then press the up arrow till you reach the 8 and put in another space. Now we have our ones and tens lined up. Digits aligned

Clone this wiki locally