When I write in my code
Action(() => someCombobox.Text = "x" )
I get this error:
Delegate ‘
System.Action<object>‘ does not take 0 arguments
Why?
This question is related to this one. I just want to understand why this error occurs.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you wish to create a
System.Actiondelegate which has no parameters and does not return a value, simply change your code to this, removing thenew Action([body]):This is because the lambda expression will return a new parameterless
System.Actiondelegate for you. EDIT: as noted by Aliostad,() => someCombobox.Text = "x"will return either a lambda expression or anAction, depending on the type of the variable you are assigning it to.EDIT: as Darin says, if you wish it to accept an argument then you need to pass that in when creating the lambda expression.