Last active
May 2, 2020 23:48
-
-
Save ThiagoBarradas/b8813be3083928a64d184f5302435eae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public enum CorSemFlags // enumerador comum | |
{ | |
Vermelho = 1, | |
Verde = 2, | |
Azul = 4, | |
Amarelo = 8 | |
} | |
[Flags] | |
public enum Cor // usando flags, basta adicionar o atributo | |
{ | |
Vermelho = 1, | |
Verde = 2, | |
Azul = 4, | |
Amarelo = 8 | |
} | |
... | |
CorSemFlags minhasCores = CorSemFlags.Vermelho | CorSemFlags.Verde | CorSemFlags.Azul; | |
Cor minhasCoresFlags = Cor.Vermelho | Cor.Verde | Cor.Azul; | |
Console.WriteLine(minhasCores); // "7" | |
Console.WriteLine(minhasCoresFlags); // "Vermelho, Verde, Azul" | |
Cor novasCores = Enum.Parse<Cor>("Vermelho, Verde, Azul"); // Funcionará e irá atribuir corretamente os valores |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment