All I have a utility method that is defined as
public static Dictionary<T, int> CountOccurences<T>(IEnumerable<T> items) { ... }
I have some legacy code that unfortunately uses ArrayList
s instead of List<T>
. Now, I need to cast the ArrayList
to use the above method and both of the following should work
var v = CountOccurences<String>(arrayList.Cast<String>().ToArray());
or
var v = CountOccurences<String>(arrayList.OfType<String>().ToArray());
Neither of these work in VS2012 under .NET 4.5 giving
'System.Collections.ArrayList' does not contain a definition for 'OfType' and no extension method 'OfType' accepting a first argument of type 'System.Collections.ArrayList' could be found (are you missing a using directive or an assembly reference?)
However, I have tested this in LINQpad and they both work. Why can't I cast my ArrayList
?
Thanks for your time.