0

Is it best practice to use the [Flags] ahead of all, even the simplest enum types like this in C# (VS 2015):

[Flags]
public enum TValidation
{
    vUninitialized, vChecksumPass, vChecksumFail, vChecksumZero, vChecksumNone
}

Am I clear such use I presented will always be ok with or without [Flags]? Or can it have some unintended side-effects?

Vlastimil Burián
  • 3,024
  • 2
  • 31
  • 52
  • Use Flags when you need it, and do not use it when you just need unique values to represent something. – user743414 Aug 22 '19 at 10:39
  • 2
    Possible duplicate of [What does the \[Flags\] Enum Attribute mean in C#?](https://stackoverflow.com/questions/8447/what-does-the-flags-enum-attribute-mean-in-c). Once you read this you’ll know why your question doesn’t make sense –  Aug 22 '19 at 10:40
  • Whether you use it or not should depend whether you're going to use the enum as a bit flag. Just applying attributes indiscriminately is never a good idea. – Diado Aug 22 '19 at 10:40
  • 2
    @DavidG *hint: it does virtually nothing* ... [not true](https://dotnetfiddle.net/VDno7v) – Selvin Aug 22 '19 at 10:41
  • @Selvin So what do you think it does that isn't virtually nothing? – DavidG Aug 22 '19 at 10:42
  • 1
    @DavidG It changes the way `ToString()` works with the enum, for starters. – Matthew Watson Aug 22 '19 at 10:42
  • @MatthewWatson Yes, that's the *something*. – DavidG Aug 22 '19 at 10:42
  • @DavidG That's the *something* which means that it doesn't do `virtually nothing`, though... – Matthew Watson Aug 22 '19 at 10:44
  • @DavidG It also makes a difference if using the enum as a property for a Control, [see here](https://stackoverflow.com/questions/15663166/using-a-ored-enum-in-a-custom-uitypeeditor). – Matthew Watson Aug 22 '19 at 10:53

0 Answers0