Saturday 12 April 2014

Enums in C#

An enum is kind of construct that you can use to make your code easier to work with. The enum construct is useful when you want to create a method that has multiple modes. A good example is the constructor for the CryptoStream class. The CryptoStream constructor accepts CryptoStreamMode.Read or CryptoStreamMode.Write as one of its arguments. This is a simple enum.

Enum is short form enumerator. Enumerating something literally means assigning numbers to it. An enum takes meaningful names and assigns numbers to them.

An enum object doesn't take up any more memory than a standard int variable, so there is no good reason not to use them to make your code clearer and easier to understand. As well as making your code more readable, enums also make methods easier to use; this makes them particularly useful in class libraries.

No comments:

Post a Comment