我有以下代码:
int[] iArray = new int[] { 2, 3, 4 };
Action<int> action = new Action<int>(ShowSquares);
Array.ForEach(iArray, action);
private static void ShowSquares(int val)
{
Console.WriteLine("{0:d} squared = {1:d}", val, val * val);
}
虽然此代码有效,但我想转换第二行
Action<int> action = new Action<int>(ShowSquares);
使用 lambda 表达式。
这可能吗?
TIA