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
var cores = Cor.Verde | Cor.Vermelho; | |
var resultado1 = cores.HasFlag(Cor.Verde); // true | |
var resultado2 = cores.HasFlag(Cor.Vermelho); // true | |
var resultado3 = cores.HasFlag(Cor.Amarelo); // false | |
var resultado4 = cores.HasFlag(Cor.Verde | Cor.Vermelho); // true, pois contém os dois |
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
[Flags] | |
public enum Cor | |
{ | |
Vermelho = 1, | |
Verde = 2, | |
// Vermelho + Verde = 1 + 2 = 3 | |
Azul = 4, | |
// Vermelho + Azul = 1 + 4 = 5 | |
// Verde + Azul = 2 + 4 = 6 | |
// Vermelho + Verde + Azul = 1 + 2 + 4 = 7 |
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
// declaração errada com valores padrões | |
[Flags] | |
public enum Cor | |
{ | |
Vermelho, // valor padrão 0 | |
Verde, // valor padrão 1 | |
Azul, // valor padrão 2 | |
Amarelo // valor padrão 3 | |
} |
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
var semCores = Cor.None; | |
var minhasCores = Cor.Azul | Cor.Verde; | |
var resultado1 = semCores.HasFlag(Cor.None); // true | |
var resultado2 = minhasCores.HasFlag(Cor.None); // true | |
var resultado3 = semCores.Equals(Cor.None); // true | |
var resultado4 = (semCores == Cor.None); // true | |
var resultado5 = (semCores == 0); // true |
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
// exemplo com flags | |
[Flags] | |
public enum Operation | |
{ | |
None = 0, // usado quando nenhum valor for atribuido | |
Read = 1, | |
Write = 2 | |
} | |
// para informar que uma operação pode ser de leitura, escrita ou ambos |
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
// Por padrão o enum herda de int (Int32) | |
// 4.294.967.296 valores diferentes | |
// ou seja -2.147.483.648 até 2.147.483.647 | |
// como tem 32 bits, para Flags, pode-se ter no máximo 32 valores diferentes | |
[Flags] | |
public enum Cor | |
{ | |
Vermelho = 1, // 1 << 0 | |
Verde = 2, // 1 << 1 |
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 |
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
// Sem flags e com uso sequencial dos números | |
// Podendo ter até 4.294.967.296 valores diferentes | |
public enum Cor | |
{ | |
Vermelho = 1, | |
Verde = 2, | |
Azul = 3, | |
Amarelo = 4, | |
Branco = 5 | |
} |
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
openssl genrsa -out mykey.pem 4096 | |
openssl rsa -in mykey.pem -pubout > mykey.pub |
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
json=' | |
{ | |
"items": [ | |
{ | |
"amount": 2990, | |
"description": "Bola do Kiko", | |
"quantity": 1 | |
} | |
], | |
"customer": { |