1
我想如果采取以下可能并结合他们:是否有包含IEnumerable或数组的约束,接口或类?
public static T[] ForEach<T>(this T[] TArray, Action<T> doWhat)
{
foreach (var item in TArray)
{
doWhat(item);
}
return TArray;
}
上述把手阵列,下面列出了处理
public static IEnumerable<T> ForEach<T>(this IEnumerable<T> TList, Action<T> action)
{
foreach (var item in TList)
action(item);
return TList;
}
有什么共同之处,无论从继承或实现为一个界面?
换句话说:您可以将数组传递给函数的第二个版本。 – 2009-08-11 21:36:09
我错过了,因为在写数组接受函数之前,我忘记了为这段代码导入我的名字空间。 – Maslow 2009-08-12 12:07:20