なぜ次DisplayContentsは、ArrayListのために(文句を言わないコンパイル)は動作しません)のArrayListとIEnumerableを問い合わせ、それは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);
}
}
}
どのようなエラーが表示されますか? – yoozer8
「Argument 1: 'System.Collections.ArrayList'から 'System.Collections.Generic.IEnumerable'に変換できません」 –
Noel