Last active
February 27, 2023 01:13
-
-
Save jpprobr/1fbe4016c4a8788642cd78c1ce45e0cb to your computer and use it in GitHub Desktop.
JPlay Demos - Conjuntos + C# + LINQ
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
int[] conjuntoA = new int[] { 1, 2, 3, 4, 5 }; | |
int[] conjuntoB = new int[] { 4, 5, 6, 7, 8 }; | |
ExibirResultado("Conjunto A", conjuntoA); | |
ExibirResultado("Conjunto B", conjuntoB); | |
var uniao = conjuntoA.Union(conjuntoB); | |
ExibirResultado("União", uniao); | |
var interseccao = conjuntoA.Intersect(conjuntoB); | |
ExibirResultado("Intersecção", interseccao); | |
void ExibirResultado(string descricao, IEnumerable<int> conjunto) | |
{ | |
Console.Write("\n{0}: ", descricao); | |
foreach (var item in conjunto) | |
Console.Write("{0} ", item); | |
} |
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
string[] funcionarios1 = new string[] { "João", "Maria", "Bruce", "Antonio", "Sonia" }; | |
string[] funcionarios2 = new string[] { "Maria", "Antonio", "Sonia" }; | |
ExibirResultado("Lista Funcionários 1", funcionarios1); | |
ExibirResultado("Lista Funcionários 2", funcionarios2); | |
var uniao = funcionarios1.Union(funcionarios2); | |
ExibirResultado("União", uniao); | |
var interseccao = funcionarios1.Intersect(funcionarios2); | |
ExibirResultado("Intersecção", interseccao); | |
void ExibirResultado(string descricao, IEnumerable<string> conjunto) | |
{ | |
Console.Write("\n{0}: ", descricao); | |
foreach (var item in conjunto) | |
Console.Write("{0} ", item); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment