using System; using System.Collections.Generic; using System.Text; namespace System.Linq { public static partial class Enumerable { public static bool Contains (this IEnumerable source, TSource value) { if (source == null) throw new ArgumentNullException ("source"); foreach (TSource element in source) if (object.Equals (element, value)) return true; return false; } public static bool Any (this IEnumerable source) { return Any (source, x => true); } public static bool Any (this IEnumerable source, Func predicate) { if (source == null) throw new ArgumentNullException ("source"); if (predicate == null) throw new ArgumentNullException ("predicate"); foreach (TSource element in source) if (predicate (element)) return true; return false; } public static bool All (this IEnumerable source, Func predicate) { if (source == null) throw new ArgumentNullException ("source"); if (predicate == null) throw new ArgumentNullException ("predicate"); foreach (TSource element in source) if (!predicate (element)) return false; return true; } public static bool SequenceEqual (this IEnumerable first, IEnumerable second) { if (first == null) throw new ArgumentNullException ("first"); if (second == null) throw new ArgumentNullException ("second"); using (var firstRator = second.GetEnumerator ()) { foreach (TSource secondElement in first) { if (!firstRator.MoveNext ()) return false; if (!object.Equals (firstRator.Current, secondElement)) return false; } if (firstRator.MoveNext ()) return false; } return true; } } }