为什么不能执行以下操作:
Func<int, int, int> sum = delegate(int x, int y = 20) { return x + y; };
Action<string, DateTime> print =
delegate(string message, DateTime datetime = DateTime.Now)
{
Console.WriteLine(message);
};
sum(x: 20, y: 40);
print(datetime: DateTime.Now, message: "Hello");
只有命名参数的情况:
Func<int, int, int> sum = delegate(int x, int y) { return x + y; };
Action<string, DateTime> print =
delegate(string message, DateTime datetime)
{
Console.WriteLine("{0} {1}", message, datetime);
};
Console.WriteLine(sum(y: 20, x: 40));
print(datetime: DateTime.Now, message: "Hello");
只有可选参数的情况:
Func<int, int, int> sum = delegate(int x, int y = 20) { return x + y; };
Action<string , DateTime> print =
delegate(string message, DateTime datetime = DateTime.Now)
{
Console.WriteLine("{0} {1}",message, datetime);
};
Console.WriteLine(sum(40));
print("Hello");