Create an IEnumerable that enumerates an array. Make sure that only enumerable stuff is used and no downcasts to ICollection are taken advantage of. - CSharp System

CSharp examples for System:Array Enumerate

Description

Create an IEnumerable that enumerates an array. Make sure that only enumerable stuff is used and no downcasts to ICollection are taken advantage of.

Demo Code


using System.Collections.Generic;
using System.Collections;
using System;// w ww  .  j ava2 s. co m

public class Main{
        /// <summary>
        /// Create an IEnumerable that enumerates an array. Make sure that only enumerable stuff
        /// is used and no downcasts to ICollection are taken advantage of.
        /// </summary>
        /// <param name="array">An array.</param>
        /// <returns>An IEnumerable cast of the array</returns>
        /// <typeparam name="T">a </typeparam>
        /// <example>The following code
        /// <code>
        /// 
        /// </code>
        /// </example>
        public static IEnumerable<T> EnumerableFromArray<T>(T[] array)
        {
            foreach (T t in array)
                yield return t;
        }
}

Related Tutorials