using System.Collections.Generic;
public static void Main()
List<string> listToValid = new List<string>(){"J'adore le .Net", "Le .Net c'est top", "Javascript non, .Net oui"};
Predicate<string> pred = IsDotNetEveryWhere;
Func<string,bool> funck = IsDotNetEveryWhere;
if (listToValid.TrueForAll(pred))
Console.WriteLine("Ah oui mais là c'est un vieux truc qui date du .Net2.0");
throw new NotSupportedException();
if (listToValid.All(funck))
Console.WriteLine("Beaucoup mieux, récent, efficace");
throw new NotSupportedException();
if (listToValid.TrueForAll(ConvertToPredicate(funck)))
Console.WriteLine("Aussi mais particulier, c'est vraiment laissé pour de la rétrocompatibilité ce truc");
throw new NotSupportedException();
IList<string> listToValidInterface = listToValid;
if (listToValidInterface.All(ConvertToFunc(pred)))
Console.WriteLine("C'est quand même mieux sur une interface");
throw new NotSupportedException();
if (listToValidInterface.All(s => IsDotNetEveryWhere(s)))
Console.WriteLine("Ouais ok j'avoue, .Net rule the world");
throw new NotSupportedException();
private static Predicate<T> ConvertToPredicate<T>(Func<T, bool> func)
return new Predicate<T>(func);
private static Func<T,bool> ConvertToFunc<T>(Predicate<T> pred)
return new Func<T,bool>(pred);
private static bool IsDotNetEveryWhere(String s)
return s.Contains(".Net");