Posts Tagged enum

Making Enums More Flexible and Extensible

Tags: , ,

Enums are great at what they do: creating a simple integer type with specific values. Their main purpose is to choose one value out of many like enum Color { Red, Green, Blue }. But what if you have data attached to those choices? What if the data is one type for one choice and another type for another choice? What if there are two pieces of data to attach to one choice and only one for another? Today’s article shows a simple pattern you can use instead of enum in these cases to get a lot more flexibility and extensibility. Read on to see how!

Read the rest of this article »

4 Comments

Enum Arithmetic and Operators

Tags: , ,

C# enum types are an easy and efficient way to make an integer type without all the overhead of something like a class or even a struct. They’re basically a synonym for an integer type like byte or int. However, that “basically” hides a lot of details that affect the way you can work with them. Today’s article explores the arithmetic and operators you are and aren’t allowed to use when you opt for an enum over an int so you’ll have a better understanding of how and how not to use them.

Read the rest of this article »

No Comments

From AS3 to C#, Part 13: Where Everything Goes

Tags: , , , ,

Today we continue the series by wrapping up C#’s class/interface/struct/enum system with a discussion of where to put them all. We’ll focus on package/namespace, organizing types into files, and some details of using/import.

Read the rest of this article »

2 Comments