Generic ForEach를 구현하는 올바른 방법은 무엇입니까?Generic ForEach를 구현하는 올바른 방법은 무엇입니까
public static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
{
if (source == null)
throw new ArgumentNullException("source");
if (action == null)
throw new ArgumentNullException("action");
foreach (T item in source)
action(item);
}
또는
public static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
{
if (source == null)
throw new ArgumentNullException("source");
if (action == null)
throw new ArgumentNullException("action");
foreach (T item in source)
{
T item0 = item;
action(item0);
}
}
그래서, 본질적으로, 당신은 X (Y)'사이 정확한지 요구하고; '및'TZ = Y; X (Z); – BoltClock
@BoltClock 내 문제는 "수정 된 클로저에 대한 액세스"입니다. –