Mega Code Archive

 
Categories / C# / Collections Data Structure
 

Convert IEnumerable to IEnumerableT

using System; using System.Collections.Generic; using System.Collections;   public static class CollectionUtils   {     public static IEnumerable<T> Convert<T>(IEnumerable oldStyleSrc) where T : class     {       foreach (object o in oldStyleSrc)       {         T elem = o as T;         if (elem != null)           yield return elem;       }     }   }