Why it's not possible to do the following :
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");
case with only named parameters :
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");
case with only optional parameters:
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");
Action
orFunc
with optional parameters (i.e. parameters with default values). – Tecu