Random Unique Numbers in C#

Balls, just spotted what it is. .Any() is only supported on IEnumerable<T> not IEnumerable

I think pretty much all LINQ stuff is only on the generic interface AFAIK.

I use this extension method to cater for the non-generic case.

Code:
        public static bool Any(this IEnumerable source)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            IEnumerator enumerator = null;

            try
            {
                enumerator = source.GetEnumerator();

                return enumerator.MoveNext();
            }
            finally
            {
                // The non-generic IEnumerator interface doesn't inherit from IDisposable
                // so we do this as a safety check
                var disposable = enumerator as IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            }
        }
 
Back
Top Bottom