为什么以下 DisplayContents 对 ArrayList 不起作用(不会编译),因为它继承了 IEnumerable 形式)
public class Program
{
static void Main(string[] args)
{
List<int> l = new List<int>(){1,2,3};
DisplayContents(l);
string[] l2 = new string[] {"ss", "ee"};
DisplayContents(l2);
ArrayList l3 = new ArrayList() { "ss", "ee" };
DisplayContents < ArrayList>(l3);
Console.ReadLine();
}
public static void DisplayContents<T>(IEnumerable<T> collection)
{
foreach (var _item in collection)
{
Console.WriteLine(_item);
}
}
}