Visual Studio C# Enum Switch Snippet – Blew My Mind

So I learned something TOTALLY COOL from a coworker today! I’m always excited about learning something new when it comes to coding.

I’ve frequently been in the situation where I’ve wanted to create a Switch statement while using enums.

So to start everything off create a generic class with an enum like this:


public class GenericClass {
    public enum ManyEnums {
        Foo, Bar, Huuuurk, Blah, FourtyTwo
    }

    public void DoSomething(ManyEnums i) {

    }
}

Inside of DoSomething type switch and then press tab. Something cool like this should automatically be generated:

While switch_on is highlighted, type i then press the down arrow. This should appear:

Blew my MIND! So much I skipped my lunch to do this blog post before I left work.

I was aware that a similar snippet existed in VB for property creation. It’s pretty awesome getting to learn something new with something you’ve been using for a really long time!

If you are aware of any other useful snippets that are built into VisualStudio, shoot them my way so I can share them!

I’m a Technology Architect for Rockfish Digital. I’ve been there since 2007. I love coding and spend most of my time in C# and JavaScript. I’m a firm believer in the Full Stack Developer.

Author: worthyd

I'm a Technology Architect for Rockfish Digital. I've been there since 2007. I love coding and spend most of my time in C# and JavaScript. I'm a firm believer in the Full Stack Developer.

4 thoughts on “Visual Studio C# Enum Switch Snippet – Blew My Mind”

  1. Wow! This can be one particular of the most beneficial blogs We have ever arrive across on this subject. Basically Fantastic. I’m also a specialist in this topic so I can understand your effort.

Leave a Reply

Your email address will not be published. Required fields are marked *