Skip to content

Instantly share code, notes, and snippets.

@jfbueno
Last active February 5, 2019 23:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfbueno/1cff5ce06fbfc3312a708f04d24a7c99 to your computer and use it in GitHub Desktop.
Save jfbueno/1cff5ce06fbfc3312a708f04d24a7c99 to your computer and use it in GitHub Desktop.
filtro-where created by jfbueno - https://repl.it/@jfbueno/filtro-where
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