[C #] take advantage IEnumerable & lt; T & gt; take-array and method allow List & lt; T & gt;

Abstract: make good use IEnumerable and array-take-all method List


Because the array with List Practice has IEnumerable interface,
the parameter declaration can-take-all method for IEnumerable and array List ,
As follows:


private void ListAllElement(IEnumerable elements)
{
    foreach (int element in elements)
    {
        Console.WriteLine(element);
    }
}

int[] a = { 1, 2, 3 };
List b = new List { 4, 5, 6 };

ListAllElement(a);
ListAllElement(b);

Of course, not only List As long as there is a practice IEnumerable interface types are available.

Original: Large column  [C #] make good use of IEnumerable <T> method to make take-array with List <T>


Guess you like

Origin www.cnblogs.com/petewell/p/11457727.html
Recommended