什么类型必须'有趣'如果没有编译错误
class Program
{
static void Main(string[] args)
{
int[] a = { 5, 3, 4 };
int sum = 0;
for (int i = 0; i < fun.Length; i++)
sum = sum + fun[i](a[i]);
Console.WriteLine(sum);
}
}
答案 0 :(得分:-5)
要使其可编辑,您可以像这样添加一个局部变量fun
:
static void Main(string[] args)
{
Func<int, int>[] fun = new Func<int, int>[0]; // <--
int[] a = { 5, 3, 4 };
int sum = 0;
for (int i = 0; i < fun.Length; i++)
sum = sum + fun[i](a[i]);
Console.WriteLine(sum);
}