Using C# enum in a switch case

Using C# enum in a switch statement can often result in cleaner code; also, it helps reduce the chances of any typo's creeping into your code.

In this post, I'm going to update the font size, font colour and section background colour by pulling the values from Umbraco and then use a C# switch case to compare the value with public enum values.

I will not be using any break default values in this example. Still, you can add them if you require a break case.

I will not show the properties and doctype for the Umbraco CMS.

Code for setting up the C# enum in a switch case.

To start, we need to create a controller, view model, helper class and view to get the values from the switch statement and display on the page.

Leave a comment



very good

Comment posted by alireza on 21 Feb 2021 07:01

Thanks, Alireza