Last active
February 5, 2019 23:23
-
-
Save jfbueno/1cff5ce06fbfc3312a708f04d24a7c99 to your computer and use it in GitHub Desktop.
filtro-where created by jfbueno - https://repl.it/@jfbueno/filtro-where
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
using System.Linq; | |
using System.Collections.Generic; | |
using static System.Console; | |
class MainClass | |
{ | |
public static void Main (string[] args) | |
{ | |
var numeros = Enumerable.Range(1, 31); | |
var pares = numeros.Where(n => n % 2 == 0); | |
var impares = numeros.Where(n => n % 2 != 0); | |
var multiplosDe3e5 = numeros.Where(n => n % 3 == 0 && n % 5 == 0); | |
var mult3e5maioresQue15 = multiplosDe3e5.Where(n => n > 15); | |
Print(pares, "Números Pares"); | |
Print(impares, "Números Ímpares"); | |
Print(multiplosDe3e5, "Múltiplos de 3 e 5"); | |
Print(mult3e5maioresQue15, "Múltiplos de 3 e 5 maiores que 15"); | |
} | |
private static void Print(IEnumerable<int> elementos, string descricao) | |
{ | |
WriteLine(new string('=', 10)); | |
WriteLine(descricao); | |
foreach(var n in elementos) | |
WriteLine(n); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment