Should lambda also support params? #7934
Answered
by
HaloFour
suugbut
asked this question in
Language Ideas
-
Action<int[]> f = (params int[] data) =>
{
foreach (var x in data)
Console.WriteLine(x);
};
f([1, 2, 3]); //ok
f(1, 2, 3); // currently produces error. Should it be supported as well? |
Beta Was this translation helpful? Give feedback.
Answered by
HaloFour
Feb 12, 2024
Replies: 1 comment
-
Lambdas do support params. The issue with your code is that you are assigning the lambda to a delegate which is not declared with var f = (params int[] data) =>
{
foreach (var x in data)
Console.WriteLine(x);
};
f(1, 2, 3); // ok |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
suugbut
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Lambdas do support params. The issue with your code is that you are assigning the lambda to a delegate which is not declared with
params
, thus that modifier is lost.