Skip to content

Instantly share code, notes, and snippets.

@Retterath
Created August 13, 2019 14:07
Show Gist options
  • Save Retterath/ee8d71df946508d24a5852f1eea49fa5 to your computer and use it in GitHub Desktop.
Save Retterath/ee8d71df946508d24a5852f1eea49fa5 to your computer and use it in GitHub Desktop.
This is just a simple example of how we can use a Predicate<T> and an Enumarable
namespace TestArea
{
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static void Main(string[] args)
{
int upperBond = int.Parse(Console.ReadLine());
List<int> numbers = Enumerable.Range(1, upperBond).ToList();
int[] input = Console.ReadLine()
.Split()
.Select(int.Parse)
.Distinct()
.ToArray();
for (int i = 0; i < input.Length; i++)
{
Predicate<int> divisible = num => { return num % input[i] == 0; };
numbers = numbers.FindAll(divisible);
}
Console.WriteLine(string.Join(" ", numbers));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment