CSharp - Converting a Legacy Collection to an IEnumerable<T> Using the Cast Operator

Description

Converting a Legacy Collection to an IEnumerable<T> Using the Cast Operator

Demo

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
class Program/*w  ww  . ja  v a 2  s  . co  m*/
{
    static void Main(string[] args)
    {
        //  We'll build a legacy collection.  
        ArrayList arrayList = new ArrayList();
        arrayList.Add("Python");
        arrayList.Add("Java");
        arrayList.Add("Javascript");

        IEnumerable<string> names = arrayList.Cast<string>().Where(n => n.Length < 7);
        foreach (string name in names)
            Console.WriteLine(name);

    }
}

Result

Related Topic