Friday, April 3, 2009

How to Properly Declare Enumeration

When delcaring the enumration in C#, you need an attribute [Flags]. Every element should have associated numeric value. There should be the None = 0 as well, and FxCop gives an warning if this part is missing.

[Flags]
public enum AttachmentTypes

{

None = 0,

Image = 1,

Video = 2,

Sound = 3,

Excel = 4,

Word = 5,

PowerPoint = 6,

Text = 7,

Xml = 8,

Application = 9,

Zip = 10,

Rar = 11,

Json = 12

}

No comments: