예제 #1
0
파일: all.cs 프로젝트: nasa03/NoAlloq
        public void readonly_span_odd()
        {
            ReadOnlySpan <int> values = stackalloc int[] {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
                11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
                21, 22, 23, 24, 25, 26, 27, 28, 29,
            };

            Assert.False(values.All(v => v % 2 != 0));
        }
예제 #2
0
        /// <summary>
        /// Determines whether all elements in this collection are equal to each other. Compares using the <see cref="object.Equals(object)"/> method.
        /// <para>This method returns true if the collection is empty or it contains only one element.</para>
        /// </summary>
        /// <typeparam name="T">The type of the elements.</typeparam>
        /// <param name="source">The collection.</param>
        /// <param name="comparer">The comparer</param>
        public static Boolean AllSame <T>(this ReadOnlySpan <T> source, IEqualityComparer <T> comparer)
        {
            if (comparer is null)
            {
                throw new ArgumentNullException(nameof(comparer));
            }

            if (source.Length <= 0)
            {
                return(true);
            }

            T first = source[0];

            return(source.All(e => comparer.Equals(first, e)));
        }
예제 #3
0
 static bool All <TSource>(this ReadOnlySpan <TSource> source, Func <TSource, bool> predicate)
 => source.All(new FunctionWrapper <TSource, bool>(predicate));